• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
rai talari
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Scott Selikoff
author
Saloon Keeper
Posts: 4007
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
graham king
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Kishantha Nanayakkara
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 489
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic