2008年9月4日

java.sql.SQLException: Result set already closed 錯誤

http://eason982.blogspot.com/2008/09/javasqlsqlexception-result-set-already.html

Statement stmt1= conn.Createstatement;
ResultSet rs1= stmt1.executeUpdate("sql指令1");
while(rs1.next()){
// to do somehting in rs1
// ...........

ResultSet rs2= stmt1.executeUpdate("sql指令2");
while(rs2.next()){
//to something in rs2
}
}



-----------------
以上在rs2迴圈之後
回到rs1迴圈時 , 原本的ResultSet rs1 會被關閉

解決辦法
--->宣告不同statement 來個別執行 ResultSet


Statement stmt1= conn.Createstatement;
Statement stmt2= conn.Createstatement;
ResultSet rs1= stmt1.executeUpdate("sql指令1");
while(rs1.next()){
// to do somehting in rs1
// ...........

ResultSet rs2= stmt2.executeUpdate("sql指令2");
while(rs2.next()){
//to something in rs2
}
}

沒有留言: