File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes connection already closed problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "connection already closed problem" Watch "connection already closed problem" New topic
Author

connection already closed problem

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
I have below code.
Method a{

Call to method b;
try{
create new connection;
call to method c(string a, Connection con);

}catch(){
}
finally{
close connection object.
}

}

method b{
create connection;
create preparedStatement;
run the sql;
in the finally block close preparedStatement and connection;
}

I am getting connection already closed exception from the method c.
Can someone tell me what am I doing wrong?

Thanks,
Trupti
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

trupti,

your description is quite mixed, or i am not able to get it properly.

your method A calls B (in method B you are creating a connection)
after processing of B again you are creating a connection and sharing it with methdo C.


now question is why are you not sharing connection with B ???

create connection before calling method B and pass the connection in method B.

Then pass same connection to method C

and in finally block of A close one connection.

I can only guess that probably you are processing some resultset or anything else which is dependant of connection created in method B.

pasting actual code here will help
[ March 15, 2005: Message edited by: Shailesh Chandra ]

Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Joe Nguyen
Ranch Hand

Joined: Apr 20, 2001
Posts: 161
It's quite possible that method c() throws an exception and close the connection which may cause by many problems including db server is down or network has been dropped. You may need to handle this type of exception in mehod b().
 
Don't get me started about those stupid light bulbs.
 
subject: connection already closed problem
 
Similar Threads
resultset is not working properly
ora-0100 maximum number of cursors exceeds
Queries regarding PreparedStatement
closing the database connection
Closing The connection (Database)