skip to main content
Designing JDBC Applications for Performance Optimization : Selecting JDBC Objects and Methods : Using get Methods Effectively

Try DataDirect Drivers Now

Using get Methods Effectively

JDBC provides a variety of methods to return data from a result set (for example, getInt(), getString(), and getObject()). The getObject() method is the most generic and provides the worst performance when the non-default mappings are specified because the JDBC driver must perform extra processing to determine the type of the value being returned and generate the appropriate mapping. Always use the specific method for the data type.
To further improve performance, provide the column number of the column being returned, for example, getString(1), getLong(2), and getInt(3), instead of the column name. If the column names are not specified, network traffic is unaffected, but costly conversions and lookups increase. For example, suppose you use:
The JDBC driver may need to convert foo to uppercase and then compare foo with all columns in the column list, which is costly. If the driver is able to go directly to result column 23, a large amount of processing is saved.
For example, suppose you have a result set that has 15 columns and 100 rows, and the column names are not included in the result set. You are interested in only three columns: EMPLOYEENAME (string), EMPLOYEENUMBER (long integer), and SALARY (integer). If you specify getString("EmployeeName"), getLong("EmployeeNumber"), and getInt("Salary"), each column name must be converted to the appropriate case of the columns in the database metadata and lookups would increase considerably. Performance improves significantly if you specify getString(1), getLong(2), and getInt(15).