How do I in JDBC read a possibly null double value from resultSet?

Option 1 is closest:

double d = rs.getDouble(1);
if (rs.wasNull()) {
  // do something
} else {
  // use d
}

It’s not very nice, but that’s JDBC. If the column was null, the double value is considered “bad”, so you should check using wasNull() every time you read a primitive that is nullable in the database.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)