我想实现把ACCES数据取出,放入对象中,再从对象导入到另一个ORACLE库中,数据取出了,但放不到对象中。代码大致如下:
String sql="select * from test"; 
ResultSet rs=stmt.executeQuery(sql); 
objTest aa = new objTest();
while(rs.next()) {
  System.out.print(rs.getString("name"));//能输出值
  String theName = rs.getString("name")
  System.out.print(theName);//不能输出值
  aa.setName(theName)
  System.out.print(aa.getName);//不能输出值
}
第一次print能输出值,说明取出了数据,为什么后面两次就不能输出了呢?

解决方案 »

  1.   

    结果集里同一行只能取了次,
    而且要从左到右地访问.
        如果想把一个值多次使用,
    可以先把它保存起来.比如:
      String theName = rs.getString("name");//保存需要的值,以便以后使用.
      System.out.print(theName);
      aa.setName(theName);
      System.out.print(aa.getName);这样就没有问题了,
      

  2.   

    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. -----------------------------------------------------------------------------------
    result set columns within each row should be read in left-to-right order, and each column should be read only once.
    -----------------------------------------------------------------------------------