For maximum portability, result set columns within each row should be read in left-to-right order, and each column should be read only once. The ResultSet interface provides getXXX methods for retrieving column values from the current row. Values can be retrieved using either the index number of the column or the name of the column. In general, using the column index will be more efficient. Columns are numbered from 1. For maximum portability, result set columns within each row should be read in left-to-right order, and each column should be read only once
String name=rs.getString(fieldname2);
String name=rs.getString(fieldname1);