• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

connection already closed problem

 
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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().
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic