java.sql.SQLException: 结果集已耗尽
我用oracle数据库,建了两个表结构如下:
单位表:id_danwei number ,name_danwei varchar2 ,其中id_danwei是主键。
人员表:id_renyuan number, id_danwei number , name varchar2 ,其中id_renyuan是主键,id_danwei是外键。
我用jsp对表管理,删除单位表中id_danwei=3的记录时,先查看人员表里是否有id_danwei=3的记录,如果有则不允许删除,如果没有则可以删除。
代码如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ include file="dbcon.jsp" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>删除</title>
</head>
<%
int id_danwei=Integer.parseInt(request.getParameter("id_danwei"));
if(id_danwei!=0){
try{
String sql_renyuan="select id_renyuan from renyuan where id_danwei="+id_danwei;
Statement stmt_renyuan=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs_renyuan=stmt_renyuan.executeQuery(sql_renyuan);
rs_renyuan.next();
int id_renyuan=rs_renyuan.getInt(1);
rs_renyuan.close();
stmt_renyuan.close();
if(id_renyuan==0){
try{
String sql="delete from danwei where id_danwei="+id_danwei;
Statement stmt=conn.createStatement();
stmt.executeUpdate(sql);
out.print("删除成功!");
stmt.close();
}catch(SQLException e){
out.print("e: "+e);
}
}
else{
out.print("单位数据不能删除,还有所属人员,请先从人员表中删除所属人员!");
out.print("<a href='danwei_show.jsp'>返回</a>");
}
conn.close();
}catch(SQLException e1){
out.print("e1: "+e1);
}
}
else{
out.print("单位ID错误,找不到数据!");
}
%>
<body>
</body>
</html>
结果报错:e1: java.sql.SQLException: 结果集已耗尽
同样的代码在mysql数据库中就可以执行,不知应该怎样解决,盼望各位高手指点,谢谢!