my dog learned polymorphism
The moose likes JDBC and Relational Databases and the fly likes JDBC Connection gets closed just after it is created. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "JDBC Connection gets closed just after it is created." Watch "JDBC Connection gets closed just after it is created." New topic
Author

JDBC Connection gets closed just after it is created.

pranesh yelkur
Greenhorn

Joined: Sep 29, 2009
Posts: 1
My application is using following way to create a statement through a connection.
1: Connection conn = null;
2: try {
3: conn = ServerUtil.getConnection();
4: ps = conn.prepareStatement(sql.toString());
5: :
6: :
7: } catch {
8: }
9: finally {
10: ServerUtil.releaseConnection();
11: }

ServerUtil is a utility class which provides method to get instance of connection and closing the connection.
But sometimes the application throws SQLException at line number 4 saying that connection is already closed.

The application is deployed in JBoss server and the ServerUtil class is getting connection from some connection pool.

Please reply back in case you need more information.
Waiting for reply.

With Regards
Pranesh Yelkur
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874

Pranesh,


ServerUtil class is getting connection from some connection pool.


We cant guess whats your ServerUtil class does. Post the class.



I suspect the connection (conn) returned from getConnection() does not have proper mechanism to handle when connection object is closed. It should check for something like this and this might be missing in your ServerUtil class

Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3740
    
  10

I agree, it sounds like ServerUtil is the problem. In normal JDBC code, once you get a connection it shouldn't be immediately closed on the next line.


[OCA 8 Book] [Blog]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC Connection gets closed just after it is created.
 
It's not a secret anymore!