我已经在机器配置了ODBC数据源,有一个technical_library数据库,里面有authors,books,auth_books
三个表.
authors: authid  ,  lastname,   firstname
books:   isbn    ,  title   ,   pub_code
auth_books:  isbn  ,  authid
auth_books表是用于前两个表的连接.
以下一段程序是用来显示author表和books表中相对应的记录.
可运行时总说:java.sql.SQLException: ResultSet is closed
请问大家一下,这是怎么回事呀谢谢了.try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); int authid;
String isbn;
connection=DriverManager.getConnection("jdbc:odbc:technical_library");
statement=connection.createStatement();

auth_books=statement.executeQuery(
              "select authid,isbn from auth_books");
                  while(auth_books.next()){             authid=auth_books.getInt("authid");
             isbn=auth_books.getString("isbn");
             authors=statement.executeQuery(
                       "select authid,lastname,firstname from authors");
             while(authors.next()){           //用来找auth_books中第一条记录的authid
                                                   //与authors表中authid相对应的记录,
             if(authid==authors.getInt("authid")){
             System.out.println(""+authid+" "+
                        authors.getString("lastname")+" "+
                        authors.getString("firstname")+" ");
                 System.out.println((++i)+"");
                 break;
             }
             }
             books=statement.executeQuery(
                                "select isbn,title,pub_code from books");
                while(books.next()){          //用来找auth_books中与books中相对应的记录.
                 if(isbn==books.getString("isbn")){
                 System.out.print(books.getString("isbn")+" "+
                                  books.getString("title")+" "+
                                  books.getString("pub_code")+" ");
                 break;
                 }
                }
            }

解决方案 »

  1.   

    使用同一个Statement时打开多个ResultSet,是不可以的,打开第二个ResultSet时,第一个自动关闭了,你可以把第一个ResultSet数据保存在一个数组或者ArrayList等里,然后再打开下一个ResultSet就可以了。
      

  2.   

    谢谢了,我知道了,
    可我没用过ArrayList,它和VECTOR和LIST是不是差不多呀.
    如果不一样的话有什么区别吗?
      

  3.   

    有些差别,看你自己习惯性用什么吧!
      在这里用可变数组比较好,因为操作是最简单的!直接赋值就可以了,而用vector跟list还要进行其它的赋值才能得到这种效果!
      用最简单的方法得到结果是效率相对要高些!
      

  4.   

    By default, only one ResultSet object per Statement object can be open at the same time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects.
      

  5.   

    难到不能连用两次authors.getString("authid")这种命令吗??
    我有两次抛出NO DATA FOUND的sql异常.这是为什么呢??