It does not really matter. A hit in the database will be many times slower than accessing column values.
rs.getString(n) will be negligible faster. However, this will depend on the driver implementation and the number of columns in the result. Most implementations are likely to use HashMap to map column names to an index, but not necessarily. In addition, some drivers can create a HashMap lazily, which means the first row will be the slowest to access by column name. JTDS, for example, performs a linear search for columns that are not already in the HashMap.
EDIT: minor changes and regrouping. No content changes.
mikeslattery
source share