views:

24

answers:

1

I have a simple query using JDBC of an Oracle database which is proving slow to retrieve, even though the query itself doesn't seem to be the problem. A profiler reveals that a lot of time is spent in:

ResultSet#getString(String)

methods, some of which are retrieving Oracle NUMBER columns which are of Java long precision, or thereabouts. These values may also be null.

I am guessing that getString(String) is slow when returning a column value that is defined as a number - and thought about using getLong(String) but of course that returns a primitive that cannot be null.

Is there a better way? Can a JDBC NUMERIC value be returned as an object without converting it to a String or incurring any other conversion cost?

+1  A: 

Something like this?

long value = resultSet.getLong(colName);
if (resultSet.wasNull()) {
   return null;
} else {
   return Long.valueOf(value);
}
skaffman
Thank you! I suppose it's not reasonable for me to have gripes about the JDBC API at this stage in the game. It does seem not optimal to have to carry out two operations for this.
EBCDIC
@EBCDIC: See http://stackoverflow.com/questions/2777214/when-accessing-resultsets-in-jdbc-is-there-an-elegant-way-to-distinguish-between
skaffman