只能使用temp.getString("name")一次,你可以保存在变量里面,而且还和查询的先后次序有关.

解决方案 »

  1.   

    引用一段JDK API:
    ...
    The ResultSet interface provides getter methods (getBoolean, getLong, and so on) 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. 
    ...
    (简单翻译一下)
    ResultSet interface 提供了getter方法用来获得当前行各列的值。这些值可以通过索引或列名来获得。通常,用列的索引会获得更高的效率。列是从1开始的。为了获得最大化的轻便,每行的列应该从左向右的顺序读取,并且每列的值只能读取一次。举例:
    while(rs.next()){
       if("male".equals( rs.getString("sex"))){  //1
           //..
       }
       if("female".equals(rs.getString("sex"))){ //2
           //..
       }
    }
    这样的话就会出错了,因为sex被读取了两次
    正确的应该这样:
    while(rs.next()){
    String sex=rs.getString("sex");
       if("male".equals(sex)){
           //..
       }
       if("female".equals(sex)){
           //..
       }
    }
      

  2.   

    先把temp.getString("name")赋值给一个变量再进行操作
      

  3.   

    有时就是可以读两次以上的,我用过,
    但有时又不可以,还没弄明白是怎么回事,
    比如说rs.beforeFirst();这个方法有时可用有时有不可用,都说rs要设置可以回滚,但不知道怎么设置,还请高人指点!