Rule Definition
While the freedom to use your column names instead of numeric constants seems like an advantage, the database itself only knows how to deal with column indexes. Therefore, each getXXX method with a column name you call must be resolved by the JDBC driver before it can be passed to the database. Because getXXX methods are typically called inside loops that could be run millions of times, this little bit of overhead can rapidly accumulate.
Remediation
Use the ResultSet getXXX methods that take numeric values instead of the versions that take column names.
Violation Code Sample
Statement st1 = con.createStatement();
ResultSet rs_new = st1.executeQuery("SELECT * FROM cars WHERE Company_name = Toyota");
System.out.println("\nOutput of executeQuery() without prepareStatement-->\n");
while (rs_new.next()) {
System.out.println(rs_new.getString("Company_name") + "\n"); // ⚠️ VIOLATION: Column label used in ResultSet getters Method as parameter
}
Fixed Code Sample
Statement st1 = con.createStatement();
ResultSet rs_new = st1.executeQuery("SELECT * FROM cars WHERE Company_name = Toyota");
System.out.println("\nOutput of executeQuery() without prepareStatement-->\n");
while (rs_new.next()) {
System.out.println(rs_new.getString(1) + "\n"); // ✅ FIXED : Column index used in ResultSet getters Method as parameter
}
Reference
IBM - Performance tips for the native JDBC driver
https://www.ibm.com/docs/en/i/7.4.0?topic=driver-performance-tips-native-jdbc#jdbcperf__title__3
Java® Platform, Standard Edition & Java Development Kit - Version 21 API Specification
https://docs.oracle.com/en/java/javase/21/docs/api/java.sql/java/sql/ResultSet.html
Related Technologies
Technical Criterion
Efficiency - SQL and Data Handling Performance
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.