java.sql.SQLException: ResultSet is closed 什么意思啊?

xyc6838 2003-06-07 12:58:04
在程序中,用完一个result后,先关闭它。想用的时候我想再开一个:ResultSet result1=stm.executeQuery("select id1 from forum where previous=\'"+topic_id+"\'");。
可是却出现如下提示:java.sql.SQLException: ResultSet is closed
请教各位?
...全文
801 30 打赏 收藏 转发到动态 举报
写回复
用AI写文章
30 条回复
切换为时间正序
请发表友善的回复…
发表回复
xyc6838 2003-06-09
  • 打赏
  • 举报
回复
问题解决了:result2=stm2.executeQuery("select id1 from forum where previous="+topic_id+"");
一切OK!谢谢大家的发言!过二天结贴,希望有高见的再来发言!!!
xyc6838 2003-06-09
  • 打赏
  • 举报
回复
但是改成这样:Statement stm2=con.createStatement();
ResultSet result2=stm2.executeQuery("select id1 from forum where previous=\'"+topic_id+"\'");
结果还是错的,出现如下提示:java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] 标准表达式中数据类型不匹配。
是不是如: acefr()和 lionlxz(狮兔) 所说的是数据类型所以不行呢,该如何解决!!
xyc6838 2003-06-09
  • 打赏
  • 举报
回复

PreparedStatement stm2=con.prepareStatement("select id1 from forum where previous=?");
stm2.setString(1,""+topic_id);
ResultSet result2=stm2.executeQuery();
取代 //ResultSet result2=stm.executeQuery("select id1 from forum where previous=\'"+topic_id+"\'");
通过了。 现在又见到 biggie(飞碟) 这样说,因该是这样的吧。
林巅峰 2003-06-09
  • 打赏
  • 举报
回复
第一个查询结束后把smt关掉,就可以了。
biggie 2003-06-09
  • 打赏
  • 举报
回复
one Statement only to be used by one Connection
一个Statement 只可以对应一个Connection
xyc6838 2003-06-09
  • 打赏
  • 举报
回复
to ldianfeng(春城池) :
关了smt?可是我还要用它啊,那是不是重新再定义一个?!Statement stm2,这样吗?感觉不行啊
xyc6838 2003-06-09
  • 打赏
  • 举报
回复
试了一下:stm.executeQuery("select id1 from forum where previous='"+topic_id+"'");
不行。我想因为有'所有\还是要的。你们说呢
xyc6838 2003-06-09
  • 打赏
  • 举报
回复
previous 是数字
acefr 2003-06-08
  • 打赏
  • 举报
回复
previous的类型=?
acefr 2003-06-08
  • 打赏
  • 举报
回复
stm.executeQuery("select id1 from forum where previous='"+topic_id+"'");
lionlxz 2003-06-08
  • 打赏
  • 举报
回复
to xyc6838(项):

你执行的SQL语句写错了:acefr()说得对,应该是
stm.executeQuery("select id1 from forum where previous='"+topic_id+"'");

previous是什么类型,字符???还是数字???




xyc6838 2003-06-07
  • 打赏
  • 举报
回复
ResultSet result2=stm.executeQuery("select id1 from forum where previous=\'"+topic_id+"\'");
难道是这句话有错吗,怎么也看不了有错啊?!!
xyc6838 2003-06-07
  • 打赏
  • 举报
回复
to lionlxz(狮兔) :
去掉以后,编译倒没出错,可是程序结果中出现如下提示:java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] 标准表达式中数据类型不匹配。
lionlxz 2003-06-07
  • 打赏
  • 举报
回复
试一下去掉try{}catch{}语句.

或者把result1和result2都放在try语句里面!

两个结果集应该在程序最后时同时关闭,这样是最正规的写法!!
xyc6838 2003-06-07
  • 打赏
  • 举报
回复
当我在查询语句加上 try catch语句后出现了错误:
try{
ResultSet result2=stm.executeQuery("select id1 from forum where previous=\'"+topic_id+"\'");
}
catch(Exception e) { out.println(e); }
if(result2.next())
{

int temp=result2.getInt("id1");
....
却出现如下错误:     Generated servlet error:
E:\Apache Tomcat 4.0\work\localhost\_\forum\view_0005ftopic$jsp.java:175: Undefined variable or class name: result2
if(result2.next())


xyc6838 2003-06-07
  • 打赏
  • 举报
回复
不行啊,也不知为什么?
sgdb 2003-06-07
  • 打赏
  • 举报
回复
那就等rs2操作完了,在关rs1、rs2
xyc6838 2003-06-07
  • 打赏
  • 举报
回复
if(result.next())
{
...
ResultSet result2=stm.executeQuery("select id1 from forum where previous=\'"+topic_id+"\'"); 
....
}
acefr 2003-06-07
  • 打赏
  • 举报
回复
???
xyc6838 2003-06-07
  • 打赏
  • 举报
回复
to acefr() :
谢谢,可是我里的  ResultSet result2=stm.executeQuery("select id1 from forum where previous=\'"+topic_id+"\'"); 这句话,是要在上一个的结果集里的程序块里的if(result.next())
{
...
(放在这里的)
....
}

加载更多回复(10)

81,092

社区成员

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

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