This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes reason for java.sql.SQLException: Closed Connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "reason for java.sql.SQLException: Closed Connection" Watch "reason for java.sql.SQLException: Closed Connection" New topic
Author

reason for java.sql.SQLException: Closed Connection

Steve Jiang
Ranch Hand

Joined: May 17, 2004
Posts: 107
I have the following code , which works fine normally. We found a exception for "java.sql.SQLException: Closed Connection" in a demo site recently. I don't understand why connection is closed , and what could be the reason.

In demo site, it happens everytime, so it looks like not other thread to close the connection.


Could anyone point me the possible reason for "java.sql.SQLException: Closed Connection" in this case?






2010-09-07 06:44:37,411logp.251 - java.sql.SQLException: Closed Connection
java.sql.SQLException: Closed Connection
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:263)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:271)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:445)
at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:3127)
at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:3042)
at sysman.util.jdbc.ConnectionWrapper.prepareStatement(ConnectionWrapper.java:577)
at sysman.emo.util.ValueResolver.getCpuCores(ValueResolver.java:805)
Sandeep Sanaboyina
Ranch Hand

Joined: Dec 14, 2009
Posts: 72
You are getting a Closed Connection exception because by line 805, your connection object m_conn is getting closed.

It won't be possible to tell why it is getting closed with the code you have provided.

Instead of using
useThat should stop the application from throwing the exception. But, to find out why the connection is closed, you will have to dig in some more ito your code.


They say you have to be the first, the best or different. I say, is it too much to ask for all three.
Steve Jiang
Ranch Hand

Joined: May 17, 2004
Posts: 107
Thanks for the reply. Since the demo site is using shiphome, we can't add the debugger for it. But in development env, we haven't met this case before. That make me very curious how the connection could be closed .



David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Someone might be closing it. As mentioned, with the code provided, there's no way to know.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: reason for java.sql.SQLException: Closed Connection
 
Similar Threads
Software caused connection abort: recv failed
Connection to database Exception
Not able to connect to the database with my JDBC program
Problem getting DB Connection from Datasource in OpenEJB
connecting to oracle db problem