Search code examples
javaresultset

Performance comparison of result set extracting data using index vs column name


Would there be a difference in performance when i use index to get data vs column name and I am talking about doing this operation a millions of times a day in the server.

rs.getString(1) vs rs.getString("columnname");

EDIT: JDBC version Oracle JDBC driver 10.2.0.4.0


Solution

  • The rs.getString(n); will perform slightly faster, because it's retrieving directly from a collection, rather than searching.

    Hundreds of future readers of your code will appreciate the rs.getString("columnname"); rather than having to look up the SQL to see what the index n refers to.