• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

connection pooling

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
{
setUser(credentials.getUser());
setPassword(credentials.getPassword());
isLoggedIn=false;
}
}
public LoginManager() throws Exception
{
connectionPool=new ConnectionPool();
connectionPool.intialize();
currentLogins=new Hashtable();
}
public boolean alreadyLoggedIn(UserCredentials credentials)
{
boolean loggedIn=false;
String user=credentials.getUser();
if(currentLogins.containsKey(user))
{
LoginProfile aProfile=(LoginProfile)currentLogins.get(user);
loggedIn=aProfile.isLoggedIn;
}
return loggedIn;
}
public boolean login(UserCredentials credentials) throws SQLException
{
if(alreadyLoggedIn(credentials))
{
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);
while(rs.next())
{
if(rs.getString(1).equals(credentials.getPassword()))
{
profile.isLoggedIn=true;
currentLogins.put(credentials.getUser(),profile);
break;
}
}
return profile.isLoggedIn;
}
}
iam trying to implement the same in the intranet project for my department..
how do we use the connection pooling ..
jyotsana
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to the JDBC Forum since there's nothing JSP specific.
bear
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Legend has it that if you rub the right tiny ad, a genie comes out.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic