c3p0-config.xml

<c3p0-config>

<named-config name="c3p0">
<property name="user">root</property>
<property name="password">hello</property>
<property name="url">jdbc:mysql://localhost:3306/frienddb</property>
<property name="driver">com.mysql.jdbc.Driver</property>

<!--数据库连接池连接数不足时,向数据库服务器申请的连接数-->

<property name="acquireIncrement">50</property>

<!--初始化连接数  -->
<property name="initialPoolSize">1</property>

<!--  最小连接数-->
<property name="minPoolSize">5</property>

<!--  最大连接数-->
<property name="maxPoolSize">50</property>

<!--  数据库连接池可以维护的statement个数-->
<property name="maxStatements">5</property>

<!--  每个连接同时可以使用的statement个数-->
<property name="maxStatementsPerConnection">5</property>
</named-config>
</c3p0-config>

package general.page.query;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class C3P0Tool {
private static ComboPooledDataSource cpds=null;

//数据库连接池只被初始化一次

static{

cpds = new ComboPooledDataSource("c3p0");

}
public static Connection getConnection() throws SQLException{

return cpds.getConnection();

}
public static void close(ResultSet rs){
if(rs!=null){
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void close(PreparedStatement prst){
if(prst!=null){
try {
prst.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void close(Connection conn){
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void close(PreparedStatement prst,Connection conn){
close(prst);
close(conn);
}
public static void close(ResultSet rs,PreparedStatement prst,Connection conn){

close(rs);
close(prst);
close(conn);

}

}

C3P0Tool的更多相关文章

  1. Servlet分页查询

    分页查询: 1.逻辑分页查询:用户第一次访问时就把全部数据访问出来,添加到一个大集合中,然后放到session中,进行转发.通过页码等的计算,把要显示的内容添加到一个小集合中,转发.遍历小集合以显示当 ...

随机推荐

  1. Netty构建游戏服务器(二)--Hello World

    一,准备工作 1,netty-all-4.1.5.Final.jar(官网下载) 2,eclipse 二,步骤概要 1,服务器开发 (1),创建Server类 该类是程序的主入口,有main方法,服务 ...

  2. 关于时间,日期,星期,月份的算法(Java中Calendar的使用方法)

    原文:http://www.open-open.com/code/view/1446195787257 package cn.outofmemory.codes.Date; import java.u ...

  3. TongWeb

    TongWeb 编辑 本词条缺少名片图,补充相关内容使词条更完整,还能快速升级,赶紧来编辑吧! 作为国内领先的中间件开发商,是国内最早研究J2EE技术和开发应用服务器产品的厂商.应用服务器TongWe ...

  4. Bootstrap全局CSS样式之button和图片

    .btn-default--button的默认样式. .btn-primary--button的首选样式: .btn-success--button的成功样式: .btn-info--button的一 ...

  5. Gas Station,转化为求最大序列的解法,和更简单简单的Jump解法。——贪心、转化

    Gas Station There are N gas stations along a circular route, where the amount of gas at station i is ...

  6. free命令具体解释——Linux性能分析

    一.使用格式 语法格式:free [-b | -k | -m] [-o] [-s delay ] [-t] [-l] [-V] [-b | -k | -m] :选择数据的单位-b字节.-k千字节.-m ...

  7. flex中dispatchEvent的用法(自定义事件) .

    Evevt和EventDispatcher类在as3的事件机制中是很重要的角色,dispatchEvent()是EventDispatcher类的一个事件发送方法,它可以发送出Event类或其子类的实 ...

  8. YII 多子域名同步登录

    a.meylou.com和b.meylou.com不做登录.c.meylou.com这个专门做用户登录.c站登录之后a,b站点同时登录. 第一步:修改php.ini配置文件,把cookie_domai ...

  9. MYSQL强制使用索引和禁止使用索引

    mysql强制索引和禁止某个索引 1.mysql强制使用索引:force index(索引名或者主键PRI) 例如: select * from table force index(PRI) limi ...

  10. Python开发【2.2 异常处理】

    1.Python常见异常类型: Exception 常规错误的基类 AttributeError 对象没有这个属性 IOError 输入/输出操作失败 IndexError 序列中没有此索引(inde ...