Java DB connection pooling

hi Experts,

Id like to set up my first database connection pool. Do you recommend using a project like Apache DBCP or create one manually?

Thoughts and suggestions are appreciated. Thank you!
LVL 10
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Is this in the context of a web app or a standalone app?
GreggAuthor Commented:
Good question! Sorry. Its a standalone app. Swing.
GreggAuthor Commented:
This is the one where i am using access. Will that complicate things?
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Hmm. Not sure if that will behave properly with a connection pool
Why don't you use one of the excellent in-memory DBs available that have proper driver support and probably *would* support connection pooling?
I don't think it will matter much if you're using Access or not as the underlying database.  Connection pooling is just being smart about re-using the connections.

I would certainly suggest using an existing connection pooler.  There's no reason to write your own as the problem is well understood and well solved by existing libraries.  We've used Apache's DBCP library for several years now in a production environment without any problems.  There's sample code on their site showing how to set it up.  It should take less than a day to get it installed and configured properly.

I'd also strongly recommend looking at the Apache QueryRunner class in their dbutils library:

It's a very nice design for avoiding the problems of leaving database connections open in the client.  Can't tell you how often I've seen other Java developers complaining about having to write JDBC code like this:

   Connection c = null ;
   try {
      c = getConnection() ;
       do database operations
    } catch (SQLException} {
    } finally {
       if (c != null) c.close() ;

All that junk vanishes if you switch to QueryRunner and you can be sure that you'll never leak connections.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GreggAuthor Commented:
Sorry for delay in responding. Thank you both.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.