我用过Oracle,Sybese都没有问题。
会不会和数据库有关,你把getInt改为getString试一下,从错误上看也有可能你已经把第一列读出来了,就不能再读了。

解决方案 »

  1.   

    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = stmt.executeQuery("SELECT * FROM TABLEname");加参数“ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE”试试
      

  2.   

    试了下,好像只有SQLserver又问题
      

  3.   

    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.
      

  4.   

    to:aaboo加了ResultSet.CONCUR_UPDATABLE就对了,我原来用的是ResultSet.CONCUR_READ_ONLY.不盛感谢:)
      

  5.   

    从ResultSet中读记录并不是一定要按照顺序来读取的,当然这得看你使用的连接数据库的方式了。
    首先,若使用odbc数据源访问数据库,理论上而言无论什么数据库,以及你是否设定Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    (即结果集支持滚动光标),应该都是要按顺序的,因为数据源访问产生的结果集是不支持滚动的。
    其次,若使用jdbc驱动访问数据库,则大多是支持滚动的,只要你设定了Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    就行,因为对于各种不同的数据库,大多的驱动都支持滚动光标。
    另外,还有既不使用odbc,也不是使用jdbc驱动访问数据库的方式,这个我不大了解,故无法说明。
      

  6.   

    不是按数据库中的顺序,而是按你在SQL语句中写的顺序
      

  7.   

    问题以解决,谢谢alphazhao的详细解答
      

  8.   

    我试过可以,代码如下。
    应该是数据库的原因
    try
    {
      Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
      Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://yourServer;DatabaseName=dbname","user","pass");  //Statement st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
      Statement st = con.createStatement();  ResultSet res = st.executeQuery("select id,name,desc from table");  while (res.next())
        System.out.println(res.getDouble("desc")+res.getString("name")+res.getInt("id") +"\n";  con.close();
    }
    catch (Exception ex)
    {
      e.printStackTrace();}