DEVFYI - Developer Resource - FYI

) How to get a field's value with ResultSet.getxxx when it is a NULL? I have tried to execute a typical SQL statement: select * from T-name where (clause); But an error gets thrown because there are some NULL fields in the table.

JDBC Interview Questions and Answers


(Continued from previous question...)

)

How to get a field's value with ResultSet.getxxx when it is a NULL? I have tried to execute a typical SQL statement:
select * from T-name where (clause);
But an error gets thrown because there are some NULL fields in the table.

You should not get an error/exception just because of null values in various columns. This sounds like a driver specific problem and you should first check the original and any chained exceptions to determine if another problem exists. In general, one may retrieve one of three values for a column that is null, depending on the data type. For methods that return objects, null will be returned; for numerics ( get Byte(), getShort(), getInt(), getLong(), getFloat(), and getDouble() ) zero will be returned; for getBoolean() false will be returned. To find out if the value was actually NULL, use ResultSet.wasNull() before invoking another getXXX method.

(Continued on next question...)

Other Interview Questions