Java DB connection pooling

Posted on 2011-10-28
Last Modified: 2013-11-23
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!
Question by:Gregg
    LVL 86

    Expert Comment

    Is this in the context of a web app or a standalone app?
    LVL 10

    Author Comment

    Good question! Sorry. Its a standalone app. Swing.
    LVL 10

    Author Comment

    This is the one where i am using access. Will that complicate things?
    LVL 86

    Expert Comment

    Hmm. Not sure if that will behave properly with a connection pool
    LVL 86

    Assisted Solution

    Why don't you use one of the excellent in-memory DBs available that have proper driver support and probably *would* support connection pooling?
    LVL 26

    Accepted Solution

    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.

    LVL 10

    Author Closing Comment

    Sorry for delay in responding. Thank you both.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Hire Top Freelancers to Complete Java Projects

    Source the talented Expert Exchange community
    for top quality work on your Java projects.

    Hire the best. Collaborate easily. Get quality work.

    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
    Video by: Michael
    Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now