When using JDBC and accessing primitive types through the result set, there is a more elegant way to handle null / 0 than the following:
int myInt = rs.getInt(columnNumber)
if(rs.wasNull())?
{
// Treat as null
} else
{
// Treat as 0
}
I personally compress whenever I see such code. I don’t understand why ResultSet was not defined to return boxed integer types (with the possible exception of performance) or at least provide both. Bonus points if anyone can convince me that the modern design of the API is great :)
My personal decision was to write a wrapper that returns Integer (I care more about the elegance of client code than performance), but I wonder if I am missing a better way to do this.
, , , , , , .