• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
mahesh lala
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you close the JDBC connection back to the Connection pool?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a question for the JDBC forum. I'll move this thread there for you.
 
Arvind Sampath
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • 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
 
Nidhi Singhal
Ranch Hand
Posts: 89
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can call close() on the connection object in the finally clause.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic