File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes What is the best way to share database connection pool? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "What is the best way to share database connection pool?" Watch "What is the best way to share database connection pool?" New topic
Author

What is the best way to share database connection pool?

LGu Gu
Greenhorn

Joined: Sep 05, 2003
Posts: 19
I have a bunch of separate Java applications running. What is the best way for them to use 1 database connection pool? Thanks!
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
It's hard to give a definitive answer w/out knowing your environment, but this often comes up in a webserver environment. If that is your case you are lucky since most webservers provide a JNDI-lookup capability, and built-in or third-party resource pooling be it JDBC connections, Mail sessions, or whatever.
It may not be useful to launch into too much detail, but in a Tomcat environment you can define a resource and then access it via a JNDI-lookup in the application (Servlet, bean, JSP, etc.)
If you provide a little more information about your runtime environment someone can give you a more detailed answer.
LGu Gu
Greenhorn

Joined: Sep 05, 2003
Posts: 19
My environment does not include any application servers or web servers, just a plain JRE.
Phil Chuang
Ranch Hand

Joined: Feb 15, 2003
Posts: 251
Well if all the applications are running in the same JVM, you could use a singleton object to control access to the connection pool.
LGu Gu
Greenhorn

Joined: Sep 05, 2003
Posts: 19
Phile: I have more than one JVM running. Each application runs as a standalone server.
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
The Sun's recommended solution is to use the JDBC2.0 DataSource facility that supports database connection pooling.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Originally posted by L Gu:
Phile: I have more than one JVM running. Each application runs as a standalone server.

Sounds like you should use RMI. You won't be able to pass the connection (they aren't serializable) so you will need to write an app to do the actual db access and pass back a RowSet object (assuming you are doing select statements).


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
LGu Gu
Greenhorn

Joined: Sep 05, 2003
Posts: 19
Thomas: First, thanks for you reply. However, If I use the solution you suggested, I have to rewrite all of my applications. So currently, I really want to just have a connection pool shared by all applications, and only replace few lines code on each application. Anybody have a good solution?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the best way to share database connection pool?
 
Similar Threads
JSF Database Access
connection pooling
To pool or not to pool, that is the question
Recognizing stale connections in connection pool
Tomcat Vs. Other Java Server Speed Issue