Clicky

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!

asked 10/28/2011 11:40

gregg_s's gravatar image

gregg_s ♦♦


14 Answers:
Is this in the context of a web app or a standalone app?
link

answered

CEHJ's gravatar image

CEHJ

Good question! Sorry. Its a standalone app. Swing.
link

answered 2011-10-28 at 09:10:28

gregg_s's gravatar image

gregg_s

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

answered 2011-10-28 at 09:13:25

gregg_s's gravatar image

gregg_s

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

answered 2011-10-28 at 09:14:12

CEHJ's gravatar image

CEHJ

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

answered 2011-10-28 at 09:33:20

CEHJ's gravatar image

CEHJ

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
link

answered 2011-10-28 at 09:34:32

dpearson's gravatar image

dpearson

Sorry for delay in responding. Thank you both.
link

answered 2011-10-29 at 13:49:09

gregg_s's gravatar image

gregg_s

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

answered 2011-11-02 at 15:22:29

CEHJ's gravatar image

CEHJ

Good question! Sorry. Its a standalone app. Swing.
link

answered 2011-10-28 at 09:10:28

gregg_s's gravatar image

gregg_s

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

answered 2011-10-28 at 09:13:25

gregg_s's gravatar image

gregg_s

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

answered 2011-10-28 at 09:14:12

CEHJ's gravatar image

CEHJ

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

answered 2011-10-28 at 09:33:20

CEHJ's gravatar image

CEHJ

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
link

answered 2011-10-28 at 09:34:32

dpearson's gravatar image

dpearson

Sorry for delay in responding. Thank you both.
link

answered 2011-10-29 at 13:49:09

gregg_s's gravatar image

gregg_s

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

Asked: 10/28/2011 11:40

Seen: 233 times

Last updated: 11/02/2011 11:22