Hands-On High Performance with Spring 5
by Chintan Mehta, Subhash Shah, Pritesh Shah, Prashant Goswami, Dinesh Radadiya
Using get methods effectively
JDBC provides different types of methods to retrieve data from a result set, such as getInt, getString, and getObject; the getObject method is the generic one, and you can use it for all data types. But, we should always avoid the use of getObject because it gives worse performance than others. When we get data with the use of getObject, the JDBC driver must perform extra processing to determine the type of value being fetched and generate the appropriate mapping. We should always use the specific method for the data type; this provides better performance than using a generic one like getObject.
We can also improve the performance by using a column number instead of a column name; for example, getInt(1), getString(2) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access