请大家帮我看看为什么会有这个异常?

ilikehere 2003-04-05 01:09:21
<%@ page language="java" import="java.sql.*"%>
<jsp:useBean id="mysql" class="byyl.dbConnection" scope="page"/>

<%
String msgID;
msgID="1";
//msgID=(String)session.getValue("ID");

String sql="select * from bbsMSG where id='"+msgID+"'";
ResultSet rs=mysql.executeQuery(sql);

rs.next();

int num=rs.getInt("replyNum");
num+=1;

rs.close();
%>

<%
String plus="update bbsMSG set replyNum='"+num+"',appTime=getDate() where id='"+msgID+"'";
mysql.executeUpdate(plus);
%>
目的是从表中查询出一个值,做处理后再用这个值来更新这条记录。
这里有异常,两条sql语句上都没什么错误,单独存在的时候正常。
但是这里放一起就不行了,不知如何解决啊,请大哥们帮忙!
...全文
42 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xfounder 2003-04-16
  • 打赏
  • 举报
回复
rs.next();

int num=rs.getInt("replyNum");
num+=1;

rs.close();

int num=0;
if(rs.next())
{
num=rs.getInt("replyNum");
num+=1;
}
rs.close();
jeston 2003-04-16
  • 打赏
  • 举报
回复
指针问题。你的connection 用的是什么连接方法???
stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY
);
如果rs没有记录,你也会发生例外。
xfounder 2003-04-16
  • 打赏
  • 举报
回复
数据类型不一致
String plus="update bbsMSG set replyNum='"+num+"',appTime=getDate() where id='"+msgID+"'";
replyNum到底是int还是string?


ilikehere 2003-04-05
  • 打赏
  • 举报
回复
没人回吗?
做过asp或者jsp的都会碰到啊,我第一次做,帮帮我吧!我等。。。。。。
ilikehere 2003-04-05
  • 打赏
  • 举报
回复
但是我的代码里就是只用到一次ResultSet

异常是这个:
javax.servlet.ServletException: [Microsoft][ODBC SQL Server Driver]????????? hstmt
哪位知道的教教我啊,我真的很痛苦.....
cgsun 2003-04-05
  • 打赏
  • 举报
回复
如不对,请指教。
cgsun 2003-04-05
  • 打赏
  • 举报
回复
mysql里的问题。
一个Statement只可以对应一个ResultSet.
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. All execution methods in the Statement interface implicitly close a statment's current ResultSet object if an open one exists.

from jdk1.4.1 api doc

<转载>
hocus 2003-04-05
  • 打赏
  • 举报
回复
把异常贴出来

81,122

社区成员

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

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