my dog learned polymorphism
The moose likes JDBC and Relational Databases and the fly likes SQLEXCEPTION: Already Closed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "SQLEXCEPTION: Already Closed" Watch "SQLEXCEPTION: Already Closed" New topic

SQLEXCEPTION: Already Closed

Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
Hi all,

Earlier i was using jvm parameters for data base connection URL, user, password. But now, i started using jboss datasource defined in jboss/default/deploy as an xml qds.xml

I am using c3po for connection pooling. When i run my application , i get following exception :
java.sql.SQLException: Already closed
at org.jboss.resource.adapter.jdbc.WrappedStatement.close(

This error is generally thrown in finally block where i am closing pstmt.close();

Interestingly, pstmt.closed is false before committing the transaction but when it invokes pstmt.close(), it finds pstmt already closed( closed=true) and throws the above execption.

It used to work fine till we started using jboss data source.

Can anyone help???
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

I am going to move this to the JDBC forum. This forum is for ORM products like TopLink and Hibernate.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
If the Connection has already been closed, then that closure would also have closed the Statement.

SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
No, connection has not been already closed. problem is with pstmt.close()
which says close() won't throw an exception if it is already closed. but it does ...

i am using jboss -4.0.4GA , i read some where if i enable aop (Aspector) it can solve my problem

but i dont know how to implement this.

Please suggest me solution for this problem

Pedro Gontijo

Joined: Sep 10, 2008
Posts: 1
Hi Patricia,

Did you find out what was the problem?
I am having the same problem here...

Thanks a lot!
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3753

I love problems like these because the exception in this case is extremely helpful. If you're getting a message that a statement is closed, then it is closed. You're task is to figure out why.

Try posting your entire JDBC code snippet (minus the queries) and/or consider in what cases other processes might be closing your objects. 9 times out of 10, connection closed can be traced to a coding error.

Ack, just realized this thread is probably dead since Patricia posted it 9 months ago... For Pedro: my comments still apply.
[ September 10, 2008: Message edited by: Scott Selikoff ]

[OCA 8 Book] [Blog]
Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
Hi Pedro,

Can you tell me the exact scenario? Are you getting this error from the initial stage or you've started to get this error when you switched to use JNDI.And kindly paste the code for better clarity.

I agree. Here's the link:
subject: SQLEXCEPTION: Already Closed
jQuery in Action, 3rd edition