小弟我最近新学JDBC如下代码:
 public static void main(String[] args) {
        try
        {
             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
             String url="jdbc:odbc:pineapple";
            cnn=DriverManager.getConnection(url);
            sta=cnn.createStatement();
            info=sta.executeQuery("select * from student where sclass='class 2'");
             System.out.println(info.getType());
            metaDate=info.getMetaData();
            System.out.println("学号   姓名    班级");
            while(info.next())
            {
                System.out.println(info.getString(1)+"  "+info.getString(2)+"  "+info.getString(3));
            }
              
            info.isBeforeFirst();
             while(info.next())
            {
                System.out.println(info.getString(1)+"  "+info.getString(2)+"  "+info.getString(3));
            }       
 }
        catch(ClassNotFoundException cnfe)
        {
            System.err.println(cnfe);
        }
        catch(SQLException sqle)
        {
            System.err.println(sqle);
        }
    }
}
当第二次查询的时候就出现了 java.sql.SQLException: Result set type is TYPE_FORWARD_ONLY
的错误,就是说只能从单方向地走,能不能让它循环的打印出来呢,我看了API找不到合适的函数(小弟 英语比较烂,呵呵)望指点一二,让它能循环的打印.谢谢

解决方案 »

  1.   

    没用过你这种方法,建议再次查之前,执行info.close();
    重新查询就可以了。或者,使用其它集合类在第一次时添充,以后想怎么用就怎么用!
      

  2.   

    楼上的效率太低
    createStatement
    Statement createStatement(int resultSetType,
                              int resultSetConcurrency)
                              throws SQLExceptionCreates a Statement object that will generate ResultSet objects with the given type and concurrency. This method is the same as the createStatement method above, but it allows the default result set type and concurrency to be overridden. Parameters:
    resultSetType - a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
    resultSetConcurrency - a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE 
    Returns:
    a new Statement object that will generate ResultSet objects with the given type and concurrency 
    Throws: 
    SQLException - if a database access error occurs or the given parameters are not ResultSet constants indicating type and concurrency
    Since: 
    1.2
      

  3.   

    循环打印的目的是什么啊!!
    困惑ing!http://www.leftworld.net/online/j2sedoc/javaref/allclasses.htm
    上面是一个中文的java API介绍
    不过估计你会失望的
    因为不可能有你要的那种函数
    小弟刚刚做过一些ResultSet的东西。所以
      

  4.   

    To : liukang520236(天堂魔鬼鬼)
    不好意思,是再次打印,谢谢你提供的URL非常好,非常感谢
      

  5.   

    To: believefym(暮色,miss,迷失,miss
    非常感谢你提供的资料,问题已经解决,谢谢