正在学jsp和servlet,写了一段servlet,编译没问题,可访问jsp时出现错误

skytears 2004-08-24 04:38:55
java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 无效的游标状态

static public boolean checkQty(String wareID,int saleQty){
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;

try{
conn = ConnectionManager.getConnection();
stmt =conn.prepareStatement("select * from Reserve where wareID=" + wareID);
rs = stmt.executeQuery();
/*此处的rs出现问题*/

if(saleQty<=rs.getInt("ResQty")){
//System.err.println("售出量大于库存量");
System.out.println("saleQty<=resQty");
return true;
}
else{
System.err.println("售出量大于库存量");
return false;
}
//return true;
}
catch(java.sql.SQLException e){
System.out.println("SaleManager Info:");
System.err.println(e);
}
finally{
if(rs!=null){
try{
rs.close();
}
catch(Exception exception){}
}
if(stmt!=null){
try{
stmt.close();
}
catch(Exception exception){}
}
if(conn!=null){
try{
conn.close();
}
catch(Exception exception){}
}
}
return false;
//System.out.println("售出量大于库存量");
}
...全文
102 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
aoplo 2004-08-24
  • 打赏
  • 举报
回复
当然了!rs初始是在第一条记录前面,你不next()一下,就rs.getInt("ResQty")肯定提示“无效的游标状态”
skytears 2004-08-24
  • 打赏
  • 举报
回复
解决,在/*此处的rs出现问题*/处加入一行:
if(!rs.next()){
return false;
}
即可
一点晴 2004-08-24
  • 打赏
  • 举报
回复


使用RS强先要激活游标状态:

即:
rs = stmt.executeQuery();
if(rs.next()){
//do sth. here
}
.....
...
skytears 2004-08-24
  • 打赏
  • 举报
回复
上面是一个类中的方法,servlet中要调用的

81,122

社区成员

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

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