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
IF(colName = NULL, 0, colName) AS colNamein theSELECTstatement (preferably in a stored proc). Philosophically this comes down to whether the DB should conform to the app, or vice versa. Since SQL handles NULLs easily and many SQL consumers do not (i.e.java.sql.ResultSet), I opt to handle it at the DB when possible. (This, of course, assumes that conceptually NULL and zero are equivalent for your purposes.) - s.co.ttNULLand Javanull. Just write... IS NOT NULLand retrieve this as abooleanvalue in JDBC. - Tech Expert Wizard