请大家帮忙看个错误!
JSP和SQL2000的程序
<%
String s=session.getAttribute( "s ").toString();
String sqlString= "select * from shouTable where s_date like '% "+s+ "% ' ";
try
{ Connection con;
Statement sql;
ResultSet rs,rs1;
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");
con=DriverManager.getConnection( "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=shangdianDB ", "sa ", " ");
sql1=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=sql.executeQuery(sqlString);
while(rs.next()){
String e_name=rs.getString( "e_name ");
String e_size=rs.getString( "e_size ");
int count=Integer.parseInt(rs.getString( "amount "));
rs1=sql.executeQuery( "select * from monthTable where e_name= ' "+e_name+ " ' and e_size= ' "+e_size+ " ' ");
rs1.next();
int receive=Integer.parseInt(rs1.getString( "receive "));
int amount=count+receive;
sql.executeUpdate( "update monthTable set receive= "+amount+ " where e_name= ' "+e_name+ " ' and e_size= ' "+e_size+ " ' ");
}
con.close();
}
catch(
SQLException e1)
{
out.print(e1);
}
%>
提示信息
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Object has been closed.
请高手指点下,谢谢!!!
------解决方案--------------------rs1=sql.executeQuery( "select * from monthTable where e_name= ' "+e_name+ " ' and e_size= ' "+e_size+ " ' ");
这句有错误!rs1不能再用sql执行,这样的话,会自动关闭rs的!
在前面定义一个
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
然后在rs.next()循环中:
rs1=stmt.executeQuery( "select * from monthTable where e_name= ' "+e_name+ " ' and e_size= ' "+e_size+ " ' ");
就可以了