"java.sql.SQLException: ResultSet is closed"错误??

tcpc2003 2003-10-16 11:19:20
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"%>
<%
//String DBDriver="COM.ibm.db2.jdbc.net.DB2Driver";
String DBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
String DBurl="jdbc:odbc:tyt";
String user="66";
String password="66";
String sql="",sql2="";
String procname="";
String logtime_start="";
String logtime_end="";
Statement stm=null;
Connection conn=null;
ResultSet rs=null,rs2=null;
try
{
Class.forName(DBDriver).newInstance();
conn=DriverManager.getConnection(DBurl,user,password);
stm=conn.createStatement();
}
catch(Exception e)
{
out.println(e.getMessage());
}
sql="select remark,process_name,log_time from wh.dp_log where remark like '%yy%' order by log_time ";
rs=stm.executeQuery(sql);
while(rs.next())
{
while(rs.getString(1).indexOf("uu")==0)
rs.next();
procname=rs.getString(2);
logtime_start=rs.getString(3);

sql2="select log_time from WH.DP_LOG where process_name='"+procname+"' and log_time>'"+logtime_start+"' and remark like '%tt%' order by log_time";
rs2=stm.executeQuery(sql2);
out.println(sql2);
rs2.close();
}
rs.close();
stm.close();
conn.close();
%>

总是说rs2已经关闭了????
谢谢
...全文
286 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
gdx 2003-10-16
  • 打赏
  • 举报
回复
1.将Statement改为PrepareStatement[不是必须]
2.每个Result对应一个PrepareStatement(Statement)
如题:
Statement stm2 = conn.createStatement();
Result rs2 = stm2.execute("your sql statement")
aku0708 2003-10-16
  • 打赏
  • 举报
回复
你 两的结果集都是同用一个连接,
RS2已经把关闭了,把RS2。CLOSE()删除了,就可以了
package com.toolsbean; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class DB { private Connection con; private PreparedStatement pstm; private String user="orich"; private String password="123456"; private String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"; private String url="jdbc:sqlserver://localhost:1433;DatabaseName=db_shopcar"; public DB(){ try{ Class.forName(driver); System.out.println("加载驱动成功"); }catch(ClassNotFoundException e){ System.out.println("加载数据库驱动失败!"); e.printStackTrace(); } } public Connection getCon(){ if(con==null){ try { con=DriverManager.getConnection(url,user,password); } catch (SQLException e) { System.out.println("创建数据库连接失败!"); con=null; e.printStackTrace(); } } return con; } /** *@功能:对数据库进行增、删、改、查操作 *@参数:sqlSQL语句;params为Object数组,里面存储的是为sql表示的SQL语句中"?"占位符赋值的数据 */ public void doPstm(String sql,Object[] params){ if(sql!=null&&!sql.equals("")){ if(params==null) params=new Object[0]; getCon(); if(con!=null){ try{ System.out.println(sql); pstm=con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); for(int i=0;iSQLException e){ System.out.println("doPstm()方法出错!"); e.printStackTrace(); } } } } /** * @功能:获取调用doPstm()方法执行查询操作后返回的ResultSet结果集 * @返回值:ResultSet * @throws SQLException */ public ResultSet getRs() throws SQLException{ return pstm.getResultSet(); } /** * @功能:获取调用doPstm()方法执行更新操作后返回影响的记录数 * @返回值:int * @throws SQLException */ public int getCount() throws SQLException{ return pstm.getUpdateCount(); } /** * @功能:释放PrepareStatement对象与Connection对象 */ public void closed(){ try{ if(pstm!=null) pstm.close(); }catch(SQLException e){ System.out.println("关闭pstm对象失败!"); e.printStackTrace(); } try{ if(con!=null){ con.close(); } }catch(SQLException e){ System.out.println("关闭con对象失败!"); e.printStackTrace(); } } public static void main(String[] args) { new DB(); } }

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧