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
GreggAsked:
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.

CEHJCommented:
Is this in the context of a web app or a standalone app?
0
GreggAuthor Commented:
Good question! Sorry. Its a standalone app. Swing.
0
GreggAuthor Commented:
This is the one where i am using access. Will that complicate things?
0
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.

CEHJCommented:
Hmm. Not sure if that will behave properly with a connection pool
0
CEHJCommented:
Why don't you use one of the excellent in-memory DBs available that have proper driver support and probably *would* support connection pooling?
0
dpearsonCommented:
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:
(http://commons.apache.org/dbutils/apidocs/org/apache/commons/dbutils/QueryRunner.html)

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.

Doug
0

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.
0
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
Java

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.