• 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

How do you close the JDBC connection back to the Connection pool?

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you close the JDBC connection back to the Connection pool?
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like a question for the JDBC forum. I'll move this thread there for you.
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

How do you close the JDBC connection back to the Connection pool?



Just make a call to the close() method on the *Connection* object you had got from the pool. While getting a connection from the pool, the Container implements the java.sql.Connection interface and gives an instance to you. When you invoke close() on this instance once you are done with the Connection object, the Container implemented close() will be called and it'll take care of the rest.

Cheers,
Arvind
 
Ranch Hand
Posts: 89
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can call close() on the connection object in the finally clause.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The question is ambiguous - do you mean "how do you close a connection" or "how do you hand it back to the connection pool"?

The previous answers assume that you want to close the connection, but if a connection pool is involved that's most likely not what you want to do. The pool implementation opens and closes connections - the client should not do that. How you hand back connections to the pool depends on the pool implementation; check its documentation.
 
Arvind Sampath
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The question is ambiguous - do you mean "how do you close a connection" or "how do you hand it back to the connection pool"?



Guess I have answered both ;)
  • To close a connection, call close()
  • In case the Connection was obtained from a pool, the container would automatically return the connection to the pool. You can check this by looking at your container API source code for the *Container-specific-Connection* class, which implements the java/sql/Connection interface. Have a look at the close() method.


  • Cheers,
    Arvind
    [ August 07, 2006: Message edited by: Arvind Sampath ]
     
    reply
      Bookmark Topic Watch Topic
    • New Topic