以下代码是我执行此应用程序时的一部分我收到无效的游标状态错误,我正在使用sql server 2005和jsp和html。
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("Jdbc:Odbc:disman");
java.sql.Statement stmt = con.createStatement();
stmt.executeUpdate("insert into earthquake(area,rictor,eqz,kms,city,state,date1,time,population,carea,farea,pland,animals,humanlife,animalsloss,sinjury,mininjury)values('"+area+"','"+rictor+"','"+eqz+"','"+kms+"','"+city+"','"+state+"','"+date1+"','"+time+"','"+population+"','"+carea+"','"+farea+"','"+pland+"','"+animals+"','"+humanlife1+"','"+animalsloss1+"','"+sinjury1+"','"+mininjury1+"')");
String items[]=request.getParameterValues("cmbitem");
int i=0;
ResultSet rs1=stmt.executeQuery("select * from earthquake");
int eid=rs1.getInt("eid");
while(i < items.length)
{ String itm=items[i];
if(itm.equals("water bottle"))
{
int totallits=rempop*3;
int totalbottles=(int)(totallits/litperbottle);
stmt.executeUpdate("insert into eq_requirement(eid,items,noitems) values('"+eid+"','"+itm+"','"+totalbottles+"'");
i++;
break;
}
else if(itm.equals("nurses"))
{
int totaldoctors=(int)(sinjury/10);
totaldoctors=(int)(totaldoctors+(mininjury/20));
int totalnurses=totaldoctors*2;
stmt.executeUpdate("insert into eq_requirement(eid,items,noitems) values('"+eid+"','"+itm+"','"+totalnurses+"'");
i++;
break;
}
else
{
out.println("<script language=javascript>alert('Earth Quake Details not added');</script>");
}
}
out.println("<script language=javascript>alert('Earth Quake Details Added Successfully');</script>");
con.close();
}
catch(Exception e)
{
out.println(e);
}
}//if update==true
}//if post event
%>
答案 0 :(得分:0)
检查您错过结束括号的插入语句
stmt.executeUpdate("insert into eq_requirement(eid,items,noitems)
values('"+eid+"','"+itm+"','"+totalbottles+"')");
还在这里,
stmt.executeUpdate("insert into eq_requirement(eid,items,noitems)
values('"+eid+"','"+itm+"','"+totalnurses+"')");
更新
ResultSet rs1=stmt.executeQuery("select * from earthquake");
while(rs1.next){
int eid=rs1.getInt("eid");
}
希望这有帮助
附注:避免sql错误的最佳方法是在执行前打印查询,并在sql开发人员中运行