MySQL Forums
Forum List  »  Stored Procedures

Re: How to return null/empty resultset from SP??
Posted by: Roland Bouman
Date: December 13, 2005 07:54PM

Just want to add that if you really are interested in getting a null through the java interface, you must use the wasNull method.

So, this:

int ret_id;
if (rs.next()) { ... this is always true
ret_id = rs.getInt("ret_id"); <---
}

is wrong, but this:

int ret_id
if (rs.next()) { ... this is always true
ret_id = rs.getInt("ret_id");
if (rs.wasNull()){
//cant use the ret_id value, it is actually null!
} else {
//safely use the ret_id value
}
}

should work.

Note that you have to "get" the value first - always. Then you should check if it actually was NULL

check it out:
http://java.sun.com/j2se/1.4/docs/api/java/sql/ResultSet.html#wasNull()



Edited 1 time(s). Last edit at 12/13/2005 07:55PM by Roland Bouman.

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: How to return null/empty resultset from SP??
1735
December 13, 2005 07:54PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.