谁用过c3p0连接池
谁用过c3p0连接池??
麻烦给个例子
------解决方案--------------------这是在spring里面的配置:
<bean id= "dataSource " class= "com.mchange.v2.c3p0.ComboPooledDataSource " destroy-method= "close ">
<property name= "driverClass " value= "oracle.jdbc.driver.OracleDriver " />
<property name= "jdbcUrl " value= "jdbc:oracle:thin:@192.168.1.10:1521:XE " />
<property name= "properties ">
<props>
<prop key= "c3p0.acquire_increment "> 5 </prop>
<prop key= "c3p0.idle_test_period "> 3000 </prop>
<prop key= "c3p0.timeout "> 5000 </prop>
<prop key= "c3p0.max_size "> 40 </prop>
<prop key= "c3p0.max_statements "> 100 </prop>
<prop key= "c3p0.min_size "> 10 </prop>
<prop key= "user "> ems </prop>
<prop key= "password "> ok </prop>
</props>
</property>
</bean>
------解决方案--------------------至少用 Hibernate
------解决方案--------------------有javabean的 下面是代码 别忘了给分 至于最后你怎么应用 还要看你灵活处理吧
private static ComboPooledDataSource condb;
static {
try {
condb = new ComboPooledDataSource();
condb.setDriverClass( "oracle.jdbc.driver.OracleDriver ";
condb.setJdbcUrl( "jdbcracle:thin192.168.0.1:1521:db ";
condb.setUser( "db ";
condb.setPassword( "db ";
condb.setAcquireIncrement(1);
condb.setMaxPoolSize(100);
condb.setMinPoolSize(2);
condb.setInitialPoolSize(2);
} catch (Exception ex) {ex.printStackTrace();}
}
------解决方案--------------------这里有个javabean的例子我自己写的,看对你有用没:
public class DBManager {
private static boolean autoCommit = false;
private static ComboPooledDataSource cpds = null;
static {
try {
configure();
} catch (Exception se) {
se.printStackTrace();
}
}
public static Connection getConnection() throws Exception {
Connection conn = cpds.getConnection();
if (conn.getAutoCommit() != autoCommit)
conn.setAutoCommit(autoCommit);
conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
if (conn == null) {
throw new Exception( "获取
连接失败! ");
}
return conn;
}
}
private static void configure() throws Exception {
cpds = new ComboPooledDataSource();
cpds.setDriverClass(设置DriverClass);
cpds.setJdbcUrl(设置Url);
cpds.setUser(设置数据库UserName);
cpds.setPassword(设置数据库Password);
cpds.setInitialPoolSize(设置MaxSize());
}
}
------解决方案--------------------顶
------解决方案--------------------厉害
------解决方案--------------------晕,还不够详细吗??
------解决方案--------------------一般采用 Application Server 的 JNDI