This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes JDBC and the fly likes How do I use a ConnectionPool for non-JEE applications? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How do I use a ConnectionPool for non-JEE applications?" Watch "How do I use a ConnectionPool for non-JEE applications?" New topic
Author

How do I use a ConnectionPool for non-JEE applications?

Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4650
    
    5

In another thread, @bear said that one should always use a ConnectionPool. I can see the good reasons for that. But when I write a simple Java application, without all the complexity of servlets, JEE, containers, etc. there are no ConnectionPool support.

How do I start?
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

check out c3p0 or BoneCP


[How To Ask Questions][Read before you PM me]
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2347
    
  28

Apache's BasicDataSource implements a connection pool
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Besides choosing a connection pool, you'll need something which runs at program startup to start the pool running. I expect each pool implementation has something like that which should hopefully be documented. And you'll have to configure the pool. And you'll have to change your application's code (if it's already written) to get its connections from the pool rather then directly from the JDBC driver.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4650
    
    5

Bill Gorder wrote:check out c3p0 or BoneCP

How in the world can one google for c3p0 and not get the droid you are looking for?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

O != 0


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

And, when I said "always", I actually meant in web apps. When you say non-JEE, do you mean Swing, or do you mean a single-threaded console application? Perhaps a connection pool may be overkill in a single-threaded console app, where you'll only need to worry about one connection at a time.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4650
    
    5

Bear Bibeault wrote:And, when I said "always", I actually meant in web apps. When you say non-JEE, do you mean Swing, or do you mean a single-threaded console application? Perhaps a connection pool may be overkill in a single-threaded console app, where you'll only need to worry about one connection at a time.


I tend to write a lot of utility programs, they will beat on the DBMS, read gigabytes of data, say for loading a complex tree of objects. If I'm going to use them, they are simple shell program driven. If I expect others, I'll use Swing and stick up a simple GUI.

But behind the startup facade, I use huge libraries of business logic that are also used in webapi with tomcat and lots of servlet stuff. Rarely is a "simple shell program" not using multiple threads, daemons, etc.

So the answer is "yes"

I want the same code to work with ten lines of Java from a shell, and tens of thousands of lines in a JEE container.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

It was last year, I think, that I converted the Swing app which is my decade-long project to use a connection pool. However I didn't use one of the connection pools which you usually see recommended for web applications, because that seemed rather like getting a 40-foot flatbed truck to bring my groceries home from the store.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I use a ConnectionPool for non-JEE applications?