rs记录集是不允许重复读的,我怀疑,你的fieldname1和fieldname2的变量内容是相同的,所以,才会有你上面说的情况,你查一下吧,一定是这样的。

解决方案 »

  1.   

    楼上说得对,记录集是不允许重复读的,而且只能按left-to-right的次序来读取数据。你看看数据库中的fieldname1是不是在fieldname2之前。如果不是,那就先读取fieldname2,再读fieldname1:
    String name=rs.getString(fieldname2);
    String name=rs.getString(fieldname1);
      

  2.   

    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