This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes connection pooling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "connection pooling" Watch "connection pooling" New topic

connection pooling

jyotsana dang
Ranch Hand

Joined: Sep 26, 2003
Posts: 135
what is connection pooling in java? i have seen a program code which uses connection pooling:
it imports the hashthable and java.lang.object:
package com;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import java.util.Hashtable;
import java.lang.Object;
public class LoginManager
private Hashtable currentLogins;
private ConnectionPool connectionPool;
private static final String SELECT_PASSWORD="SELECT password FROM idpassword WHERE userid=";
private static final String QUOTE="'";
private class LoginProfile extends UserCredentials
boolean isLoggedIn=false;
public LoginProfile(UserCredentials credentials)
public LoginManager() throws Exception
connectionPool=new ConnectionPool();
currentLogins=new Hashtable();
public boolean alreadyLoggedIn(UserCredentials credentials)
boolean loggedIn=false;
String user=credentials.getUser();
LoginProfile aProfile=(LoginProfile)currentLogins.get(user);
return loggedIn;
public boolean login(UserCredentials credentials) throws SQLException
return false;
LoginProfile profile=new LoginProfile(credentials);
Connection con=connnectionPool.getConnection();
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(SELECT_PASSWORD+QUOTE+credentials.getUser()+QUOTE);
return profile.isLoggedIn;
iam trying to implement the same in the intranet project for my department..
how do we use the connection pooling ..
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63349

Moving this to the JDBC Forum since there's nothing JSP specific.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Joe Ess

Joined: Oct 29, 2001
Posts: 9150

Where did you get that code? They probably provided the code for the ConnectionPool class as well. Connections are expensive to allocate in Java, so it is a common practice to open a few and keep them around in a pool to reuse. If you are using Oracle, a pool is implemented as oracle.jdbc.pool.OracleDataSource. If you aren't, you do have that ConnectionPool class.

[How To Ask Questions On JavaRanch]
I agree. Here's the link:
subject: connection pooling
It's not a secret anymore!