C3P0连接池
来源:互联网 发布:多媒体管理系统 源码 编辑:程序博客网 时间:2024/06/09 14:58
C3P0连接池:
最常用的连接池技术!Spring框架,默认支持C3P0连接池技术!
C3P0连接池,核心类:
CombopooledDataSource ds;
jar:
c3p0-0.9.1.2.jar
硬编码:
@Test public void testCode() throws Exception { // 创建连接池核心工具类 ComboPooledDataSource dataSource = new ComboPooledDataSource(); // 设置连接参数:url、驱动、用户密码、初始连接数、最大连接数 dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/jdbc_demo"); dataSource.setDriverClass("com.mysql.jdbc.Driver"); dataSource.setUser("root"); dataSource.setPassword("root"); dataSource.setInitialPoolSize(3); dataSource.setMaxPoolSize(6); dataSource.setMaxIdleTime(1000); // ---> 从连接池对象中,获取连接对象 Connection con = dataSource.getConnection(); // 执行更新 con.prepareStatement("delete from admin where id=7").executeUpdate(); // 关闭 con.close(); }
xml配置:
@Test public void testXML() throws Exception { // 创建c3p0连接池核心工具类 // 自动加载src下c3p0的配置文件【c3p0-config.xml】 ComboPooledDataSource dataSource = new ComboPooledDataSource();// 使用默认的配置 //有参数的情况是对用xml文件的名字 // 获取连接 Connection con = dataSource.getConnection(); // 执行更新 con.prepareStatement("delete from admin where id=5").executeUpdate(); // 关闭 con.close(); }}
xml文件:
<c3p0-config> <default-config> <property name="jdbcUrl">jdbc:mysql://localhost:3306/jdbc_demo </property> <property name="driverClass">com.mysql.jdbc.Driver</property> <property name="user">root</property> <property name="password">root</property> <property name="initialPoolSize">3</property> <property name="maxPoolSize">6</property> <property name="maxIdleTime">1000</property> </default-config> <named-config name="oracle_config"> <property name="jdbcUrl">jdbc:oracle:thin:@localhost:1521:jdbc_demo</property> <property name="driverClass">oracle.jdbc.driver.OracleDriver</property> <property name="user">root</property> <property name="password">root</property> <property name="initialPoolSize">3</property> <property name="maxPoolSize">6</property> <property name="maxIdleTime">1000</property> </named-config></c3p0-config>
0 0
- C3P0连接池
- c3p0 连接池配置
- C3P0连接池配置
- C3P0连接池
- C3P0连接池
- C3P0连接池配置
- c3p0连接池
- C3p0连接池
- C3P0连接池例子
- Spring C3P0 连接池
- c3p0 连接池配置
- c3p0连接池使用
- c3p0连接池配置
- c3p0连接池
- JDBC连接池C3P0
- c3p0连接池
- C3P0连接池配置
- C3P0连接池配置
- 1000
- Hacking the PS4, part 1
- 线程-ThreadLocal-线程局部变量
- [BASIC-3]-字母图形-(java)
- 我的第一个博客
- C3P0连接池
- Virtualenv和Virtualenvwrapper安装和使用(Mac)
- 文献检索、整理、归纳
- codeforces----2017 Hackatari Codeathon(A 暴力搜索 G概率)(水题DEH)
- jquery.extend()详解
- js如何截取字符串
- 关系数据库设计理论(二)函数依赖的规则
- 挪威的木头
- 二、构建Spring源码环境