开发者

How can I retrieve a JDBC NUMERIC column value that may be NULL, without incurring a conversion cost?

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:

Res开发者_Python百科ultSet#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?


Something like this?

long value = resultSet.getLong(colName);
if (resultSet.wasNull()) {
   return null;
} else {
   return Long.valueOf(value);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜