Magical WebLogic, Connection closed and result set already closed!

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.