Connection Pool
843854Oct 27 2003 — edited Nov 20 2014Help!!
I have a JSP, java classes web application connectiong to oracle 9 database. I have 20 java classes in my application. In my JSP pages, I call methods from the java classes. All these java classes extend my connectBean which is an abstract class and has a makeconnection() method which connects to the database. This connectBean also has a method cleanUp() which is overridden by all my java classes.
I am implementing OracleConnectionPoolDataSource object in this bean but it is not working like I want it to work. Though I am closing every connection as soon as I am done with that, there are several inactive ones left in oracle database.
This is my connectBean object code. Please help me to add proper connection pool code into this bean.
package almisWeb;
import java.sql.*;
import javax.sql.PooledConnection;
import gov.utah.dws.util.*;
import java.util.Properties;
import java.util.*;
import java.net.URL;
import javax.sql.*;
public abstract class connectBean
{
protected Connection connection;
protected PooledConnection pc;
public connectBean()
{
} // empty constructor
public void makeConnection() throws Exception
{
try
{
String fileName = "production.properties";
URL url = Thread.currentThread().getContextClassLoader().getResource(fileName);
String fullFileName = url.getFile();
LoadProperties lp = new LoadProperties(fullFileName);
Properties props = lp.getProperties();
OracleConnectionPoolDataSource ocpds = new OracleConnectionPoolDataSource();
ocpds.setURL(props.getProperty("url"));
ocpds.setUser(props.getProperty("user"));
ocpds.setPassword(props.getProperty("password"));
ocpds.setDriverType(props.getProperty("driver"));
pc = ocpds.getPooledConnection();
connection = pc.getConnection();
}
catch(Exception e)
{
e.printStackTrace();
System.err.println("Class Not Found" + e);
}
} // end method makeConnection
public abstract void cleanup() throws Exception;
public void goDown() throws Exception
{
cleanup();
if(connection != null)
{
connection.close();
connection = null;
pc.close();
pc = null;
}
}
}// end of class connectBean
Thanks for any help
Suraj