Java.sql.SQLException: After end of result set错误

zhaozhihua123 2009-08-27 10:46:37
大家帮我看一下,下面这段代码到底错在哪里啊?老是提示标题上的错误,我都快郁闷死了!

public String update() throws Exception{
String sql="select boardid,boardtype from board";
DBConnect dbc1=new DBConnect(sql);
ResultSet rs=dbc1.executeQuery();
StringBuffer sb=new StringBuffer();
if(!rs.next()){
dbc1.close();
throw new Exception("论坛还没有版面,请先添加版面。");
}
// temprs;
DBConnect dbc=new DBConnect();
String newuser=newuser(dbc);
do{

sql="Select count(announceid) from bbs1 where boardid="+rs.getInt(1);
ResultSet temprs=dbc.executeQuery(sql);

temprs.next();
String tempString=temprs.getString(1);
int allArticle=(tempString==null)?0:temprs.getInt(1);

temprs=dbc.executeQuery("Select count(announceid) from bbs1 where boardid="+rs.getInt(1) +" and parentID=0");
temprs.next();
tempString=temprs.getString(1);
int allTopic=(tempString==null)?0:temprs.getInt(1);

ResultSet ers=dbc.executeQuery("select Max(announceid) from bbs1 where boardid="+rs.getInt(1));
ers.next();
tempString=ers.getString(1);

//int maxID=(tempString==null)?"无":ers.getInt(1);
String userName,dateandtime;


if(tempString==null){
userName="无";
dateandtime=Format.getDateTime();
}
else {
int maxID=ers.getInt(1);
ers=dbc.executeQuery("select username,dateandtime from bbs1 where announceid="+maxID);
ers.next();
userName=ers.getString(1);
dateandtime=ers.getString(2);
}

sql="update board set lastpostuser=?,lastposttime='"+dateandtime+"',lastbbsnum="+allArticle+",lasttopicnum="+allTopic+",TodayNum="+todays(rs.getInt(1),dbc)+" where boardid="+rs.getInt(1);
dbc.prepareStatement(sql);
dbc.setBytes(1,userName.getBytes("GBK"));
dbc.executeUpdate();
sb.append("更新论坛数据成功,"+rs.getString(2)+"共有"+allArticle+"篇贴子,"+allTopic+"篇主题,今日有"+todays(rs.getInt(1),dbc)+"篇帖子。<br>");
}
while(rs.next());
sql="update config set TopicNum="+titlenum(dbc)+",BbsNum="+gettipnum(dbc)+",TodayNum="+alltodays(dbc)+",UserNum="+allusers(dbc)+",lastUser=?";
dbc.prepareStatement(sql);
dbc.setBytes(1,newuser.getBytes("GBK"));
dbc.executeUpdate();
dbc.close();
dbc1.close();
ForumPropertiesManager.resetManager();
return sb.toString();

}
...全文
943 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
xtbzqw 2009-08-27
  • 打赏
  • 举报
回复
你可以共用一个ResultSet,你在用完一个ResultSet以后,然后close掉,就可以接着用!
zhaozhihua123 2009-08-27
  • 打赏
  • 举报
回复
试过了,不是上面的问题!我搜索了一下百度,上面说是因为resultset的问题,不能同时使用,但又不知道怎么解决!
monkeyking1987 2009-08-27
  • 打赏
  • 举报
回复
sql="Select count(announceid) from bbs1 where boardid="+rs.getInt(1);
ResultSet temprs=dbc.executeQuery(sql);

temprs.next();
String tempString=temprs.getString(1);
int allArticle=(tempString==null)?0:temprs.getInt(1);
看SQL语句,SQL语句只返回有一个值,即统计的数量,而下面则调用了两次getXXX方法。肯定会出错了。
lcj_up 2009-08-27
  • 打赏
  • 举报
回复
应该是越界错误!!!
bayougeng 2009-08-27
  • 打赏
  • 举报
回复
从你的error信息来看,确实是越界了。
应该就是在某个next()方法上抛出的。
把异常的详细信息,以及抛异常的那条代码都贴出来。
gukuitian 2009-08-27
  • 打赏
  • 举报
回复
空的rs不是这个错,
是rs有值,你一.next()到最后又getString()的错,


错误拿出来看看,就知道哪个rs 的错了
非典型射手 2009-08-27
  • 打赏
  • 举报
回复

int maxID=ers.getInt(1);
ers=dbc.executeQuery("select username,dateandtime from bbs1 where announceid="+maxID);
ers.next();
userName=ers.getString(1);
dateandtime=ers.getString(2);



最有可能出现问题的是这里。next方法你都没有判断返回值,不过之前的sql语句都是聚合函数,应该都有一条记录。不过上面这条语句可能是没有值的,这个时候再去getString可能会出错
gukuitian 2009-08-27
  • 打赏
  • 举报
回复
取出你的要的值后
rs.close();
zhaozhihua123 2009-08-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 xtbzqw 的回复:]
你可以共用一个ResultSet,你在用完一个ResultSet以后,然后close掉,就可以接着用!
[/Quote]

如何共用?我觉得最关键的应该是resultset rs那里有错!
xinyung 2009-08-27
  • 打赏
  • 举报
回复
这里进行了两次赋值:
ResultSet temprs=dbc.executeQuery(sql);
temprs=dbc.executeQuery("Select count(announceid) from bbs1 where boardid="+rs.getInt(1) +" and parentID=0");

81,092

社区成员

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

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