The answer was accepted, however, here is some additional information and personal experience that I have not yet seen.
Use column names (constants rather than literals are preferred) in general and, if possible. This becomes more understandable, easier to maintain, and future changes are less likely to break the code.
However, for column indices it is used. In some cases, this is faster, but not enough to override the above reasons for names *. This is very valuable when developing tools and general methods for working with ResultSet s. Finally, an index may be required because the column does not have a name (for example, an unnamed aggregate) or there are duplicate names, so there is no easy way to refer to both.
* Note that I wrote several JDBC drivers and peered at some open source sources internally, using column indexes to reference result columns. In all the cases I worked with, the internal driver first maps the column name to the index. Thus, you can easily see that the column name in all of these cases will always take longer. This may not be true for all drivers.
Kevin Brock Feb 04 '10 at 5:10 2010-02-04 05:10
source share