用c3p0数据源来做,先导入c3p0的包,用g_DataSourcePool.getConnection()就可以获得数据库连接了
package com.like.loft;
import java.beans.PropertyVetoException;
import com.mchange.v2.c3p0.ComboPooledDataSource;
/**
* Oracle数据库连接池
*
*
*
* @author like
* @version [版本号, 2015-10-8]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
public class OracleDbConnPool
{
/*
* 数据库连接池
*/
public static ComboPooledDataSource g_DataSourcePool;
public static ComboPooledDataSource createPooledDataSource()
{
//创建连接池实例
ComboPooledDataSource ds = new ComboPooledDataSource();
try
{
//设置连接池所需的驱动
ds.setDriverClass("oracle.jdbc.driver.OracleDriver");
//设置连接数据库的URl
ds.setJdbcUrl("jdbc:oracle:thin:@192.168.0.203:1521/ecms");
//设置用户名
ds.setUser("dsims");
ds.setPassword("1");
ds.setMaxPoolSize(40);
ds.setMinPoolSize(2);
ds.setInitialPoolSize(10);
ds.setMaxStatements(100);
}
catch (PropertyVetoException e)
{
e.printStackTrace();
}
return ds;
}
public static ComboPooledDataSource getG_DataSourcePool()
{
return g_DataSourcePool;
}
public static void setG_DataSourcePool(ComboPooledDataSource g_DataSourcePool)
{
OracleDbConnPool.g_DataSourcePool = g_DataSourcePool;
}
}