我已经在机器配置了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;
}
}
}
三个表.
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;
}
}
}
解决方案 »
- 请问java多线程的线程切换的最小单元是什么,是语句还是代码块
- 有什么数据库是不用配置的,难不成只有txt和XML存储数据了
- xterm 复制粘贴全选
- MyEclipse和Eclipse下下来了怎么安装?直接覆盖吗?
- 类型不匹配错误。利用Java反射技术将查询结果封装为对象
- 看一下我的程序--多线程比较排序算法的快慢
- JSpinner问题,很简单,高手一看就可以轻松拿分了,小弟不会呀,着急!!!!!!!!!!!!!!!
- 希望得到大家的指点提供思路和方法!!!!!!!!!!!!!!
- 一个list中remove方法的问题
- 如何用java实现特定时间的程序运行!
- 帮忙看看老师的作业
- 初学者的问题...大家给个答案 ....
可我没用过ArrayList,它和VECTOR和LIST是不是差不多呀.
如果不一样的话有什么区别吗?
在这里用可变数组比较好,因为操作是最简单的!直接赋值就可以了,而用vector跟list还要进行其它的赋值才能得到这种效果!
用最简单的方法得到结果是效率相对要高些!
我有两次抛出NO DATA FOUND的sql异常.这是为什么呢??