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), and getLong(3). If we are using a column name instead of a column number (for example, getString("accountName")), then the database driver first converts the column name to uppercase (if required), then compares accountName with all columns available in the result set. This processing time directly impacts performance. We should reduce that processing time with the use of column numbers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset