aspose file tools*
The moose likes JDBC and the fly likes java.sql.SQLException: Connection handle has been closed and is unusable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.sql.SQLException: Connection handle has been closed and is unusable" Watch "java.sql.SQLException: Connection handle has been closed and is unusable" New topic
Author

java.sql.SQLException: Connection handle has been closed and is unusable

rai talari
Ranch Hand

Joined: Jan 31, 2006
Posts: 34
hi iam using jboss 3.2.3 it is giving sqlexception as "java.sql.SQLException: Connection handle has been closed and is unusable" .what may be the problem pls notify me


nothing is impossible in the world even the word impossible sounds as I'M'Possible.
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3710
    
    5

Tempted to move this to the JBoss forum (you might find more help there) but it is probably a JDBC issue.

Are you using connection pooling or direct JDBC? The error your describing is if the database connection has been closed. I'm not sure why you are trying to read a closed database connection instead of opening a new one, but we'd likely need to see some code or hear more information to help.


My Blog: Down Home Country Coding with Scott Selikoff
graham king
Ranch Hand

Joined: Dec 30, 2004
Posts: 133
Originally posted by rai talari:
hi iam using jboss 3.2.3 it is giving sqlexception as "java.sql.SQLException: Connection handle has been closed and is unusable" .what may be the problem pls notify me


rai,

there's a setting in the yourapp-ds.xml file that allows for a reconnection to the database. i think this error is encountered when a network connection from the app server to the db server breaks, or, when the db server is restarted and the app server isn't.

have a look:


taken from a jboss4.0.2serverinstalldir/docs/examples/jca/mysql-ds.xml

hope it helps


write, revise, re-write, revise, again...<br />write, revise, re-write, revise, again...
Kishantha Nanayakkara
Greenhorn

Joined: Jun 25, 2009
Posts: 2
This can be due to the way you handle the transactions. If you try to handle transactions manually with setAutoCommit() and at the same time try to use session beans which in turn do some
database operations using the datasource or entity beans or any other way this can happen.

Solution is to use JTA transactions for your manual transaction part. Following code snippet explains how.


UserTransaction ut = (UserTransaction) c.lookup("java:comp/UserTransaction");


try {
ut.begin();

//insert your database manipulation code here.
//insert your session beans access code here.

ut.commit();
} catch (Throwable ex) {
try {
ut.rollback();
} catch (SystemException syex) {
throw new Exception( "Rollback failed: " + syex.getMessage());
}
throw new Exception( "Transaction failed: " + ex.getMessage());
}

You can refer to my blog for more information.

http://kishantha.blogspot.com/2009/06/mixing-transactions-manual-and.html
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

@Kishantha..

How to mixing JTA with Hibernate Template (session) ?.. is it possible?..
May you give me an example?..
i want to make a transaction like this.. (Quoted from your post before)



Do i have to use sessionFactory?

Thanks in advance sir..

Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.sql.SQLException: Connection handle has been closed and is unusable