Checking for a null int value from a Java ResultSet
Posted
by ian_scho_es
on Stack Overflow
See other posts from Stack Overflow
or by ian_scho_es
Published on 2010-05-27T10:42:19Z
Indexed on
2010/05/27
10:51 UTC
Read the original article
Hit count: 224
In Java I'm trying to test for a null value, from a ResultSet, where the column is being cast to a primitive int type.
int iVal;
ResultSet rs = magicallyAppearingStmt.executeQuery(query);
if (rs.next()) {
if (rs.getObject("ID_PARENT") != null && !rs.wasNull()) {
iVal = rs.getInt("ID_PARENT");
}
}
From the code fragment above, is there a better way to do this, and I assume that the second wasNull() test is redundant?
Educate us, and Thanks
© Stack Overflow or respective owner