cbj
cbj

Reputation: 37

How to Create A Connection Pool/Data Source rather than connecting to A SQL DB

I have code that connects to a SQL DB and queries it based on user input. I would like to connect using a Pool instead to speed up the query times. I attempted to write a Pool and Manager class but I am getting an unreported NamingException when I try to get a connection from the pool. I have also already caught NamingExceptions in my getConnection() function.

Does anyone know why I am getting this error?

Or could point me in the right direction to create a valid ConnectionPool?

Upvotes: 0

Views: 392

Answers (2)

Andreas Veithen
Andreas Veithen

Reputation: 9154

You have 3 options:

  • If your code runs in an application server, configure a connection pool in the server.
  • Some JDBC drivers provide a connection pool implementation (but many only provide a poolable data source that is meant for integration with an app server).
  • Use commons-dbcp or some equivalent library to create a connection pool.

Upvotes: 0

jmoreno
jmoreno

Reputation: 13561

You should use the latest JDBC driver, which supports connection pooling internal, so you don't have to write your own.

Upvotes: 1

Related Questions