通过jsp+servlet+bean实现数据库查询
源代码在线查看: connpool.java
package shared;
import java.sql.Connection;
import java.sql.SQLException;
import oracle.jdbc.pool.OracleConnectionCacheImpl;
public class ConnPool
{
private OracleConnectionCacheImpl oracleConnectionPool = null;
private String Url = null;
private String Name = null;
private String Pwd = null;
private int maxCount = 0;
public ConnPool(String Url, String Name, String Pwd, int maxCount)
{
try
{
this.Url = Url;
this.Name = Name;
this.Pwd = Pwd;
this.maxCount = maxCount;
oracleConnectionPool = new OracleConnectionCacheImpl();
oracleConnectionPool.setURL(Url);
oracleConnectionPool.setUser(Name);
oracleConnectionPool.setPassword(Pwd);
oracleConnectionPool.setMaxLimit(maxCount);
}
catch(SQLException sqlExp)
{
sqlExp.printStackTrace();
}
catch(NumberFormatException numFmtExp)
{
numFmtExp.printStackTrace();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
public Connection getConnection()
{
Connection conn = null;
try
{
if ( null != oracleConnectionPool)
{
synchronized(oracleConnectionPool)
{
conn = oracleConnectionPool.getConnection();
}
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
return conn;
}
}