Recently, a new set of Java encapsulation classes emerged during the runtime. SQL. sqlexception: result set already closed "error. It has a high probability of occurrence, but it is random. After commenting out the close code of resultset, the problem persists.
The connection code is as follows:
Javax. Naming. Context initctx = new javax. Naming. initialcontext ();
Javax. SQL. datasource DS = (javax. SQL. datasource) initctx. Lookup (_ jndi_name );
If (Ds! = NULL ){
_ Conn = Ds. getconnection ();
// Return _ conn;
}
The query code is as follows:
Statement Sm = _ conn. createstatement (resultset. type_forward_only, resultset. concur_read_only );
Resultset rs = sm.exe cutequery (sqltext );
It is said on the Internet that some problems may occur when the same statement is run twice. In the csdn Forum, do not directly return the resultset; instead, return the list:
List list = new arraylist ();
Connection conn = NULL;
Statement stmt = NULL;
Resultset rs = NULL;
Try
{
Conn = openconnection ();
Stmt = conn. createstatement ();
Rs = stmt.exe cutequery (SQL );
Resultsetmetadata rsmd = Rs. getmetadata ();
While (Rs. Next ())
{
Map map = new hashmap ();
For (INT I = 1; I <= rsmd. getcolumncount (); I ++)
{
Map. Put (rsmd. getcolumnname (I), RS. getstring (I) = NULL? "": Rs. getstring (I ));
}
List. Add (MAP );
}
}
Catch (exception E)
{
E. printstacktrace ();
}
Finally
{
If (RS! = NULL) Rs. Close ();
Closeconnection (conn );
}
Return list;
See: http://topic.csdn.net/t/20040816/23/3280711.html
Obviously, none of the above is a fundamental solution to the problem. When you view the encapsulation class code, make sure the problem lies in finalize:
Public class basepage {
Protected void finalize ()
{
........
Database. Disconnect ();
}
}
This is the code written due to programming habits. The problem disappears after the annotation.