[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Java DB connection pooling

Posted on 2011-10-28
7
Medium Priority
?
299 Views
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!
0
Comment
Question by:Gregg
  • 3
  • 3
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 37045776
Is this in the context of a web app or a standalone app?
0
 
LVL 10

Author Comment

by:Gregg
ID: 37045800
Good question! Sorry. Its a standalone app. Swing.
0
 
LVL 10

Author Comment

by:Gregg
ID: 37045808
This is the one where i am using access. Will that complicate things?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 86

Expert Comment

by:CEHJ
ID: 37045950
Hmm. Not sure if that will behave properly with a connection pool
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 1000 total points
ID: 37045959
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
 
LVL 28

Accepted Solution

by:
dpearson earned 1000 total points
ID: 37051031
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
 
LVL 10

Author Closing Comment

by:Gregg
ID: 37073390
Sorry for delay in responding. Thank you both.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month20 days, 2 hours left to enroll

872 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