Bug #27442 ResultSet.wasnull method returns false for even null Blob field in DB
Submitted: 26 Mar 2007 13:10 Modified: 26 Mar 2007 13:17
Reporter: tarik karaoglu Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:3.1.14 OS:Windows (Windows XP Pro + SP2)
Assigned to: CPU Architecture:Any
Tags: java.sql.Blob, ResultSet, wasNull method

[26 Mar 2007 13:10] tarik karaoglu
Description:
I work on MySQL server 5.0 and MySQL Connector/J 3.1.14 and Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_10-b03). 

When I call java.sql.ResultSet interface wasNull method on an empty Blob value like that
========================================================================
1 if (!resultSet.wasNull()) {
2    		 java.sql.Blob blob =  resultSet.getBlob(names[0]);
3   		 if(blob==null){
4    			 //something is wrong
5    			 return null;
    		 }
=========================================================================

Although it passes over control and resultSet.wasNull() returns false, blob is actually null in table and throws exception when blob field is accessed.

How to repeat:
Just setup this environment and access a null blob field.
[26 Mar 2007 13:17] Mark Matthews
You have the order of the calls wrong. You can't call .wasNull() until _after_ you try and retrieve the value (and thus it doesn't make much sense to use it for ResultSet accessors that return object instances, since you can just do the normal "== null" check.

From the apidocs:

"Reports whether the last column read had a value of SQL NULL. Note that you must first call one of the getter methods on a column to try to read its value and then call the method wasNull to see if the value read was SQL NULL. "