Reputation: 5247
I have an sql column PROTOCOL of Number type .It is nullable and a constraint on the table PROTOCOL IN(1,2,3).I am able to set to null. How to get the value if its null? I can do rs.getInt() but I dont think it returns null?
if(protocol==0)
{
stmt.setNull(15, java.sql.Types.INTEGER);
}
else{
stmt.setInt(15, protocol);
}
Upvotes: 0
Views: 442
Reputation: 36630
I can do rs.getInt() but I dont think it returns null?
Use ResultSet.wasNull() after getInt()
to check if the last column read was NULL.
Or, use ResultSet.getObject() instead of getInt()
, which returns null
if the column is NULL
.
Upvotes: 3
Reputation: 24885
Use wasNull()
method.
Integer myValue = rs.getInt(15);
if (rs.wasNull()) {
myValue = null;
}
Upvotes: 4