zoukankan      html  css  js  c++  java
  • C3P0连接池

    C3P0是一个开源的JDBC连接池,它实现了数据源和JNDI绑定,支持JDBC3规范和JDBC2的标准扩展。目前使用它的开源项目有Hibernate,Spring等

    使用C3P0配置数据库连接池

     

    配置文件:c3p0-config.xml 
    <c3p0-config>
    <named-config name="dbInfo">
    <!—配置用户名密码、连接、驱动
    <property name="user">admin</property>
    <property name="password">admin</property>
    <property name="jdbcUrl">jdbc:mysql:///blog</property>
    <property name="driverClass">com.mysql.jdbc.Driver</property>
    
    <!--数据库连接池一次向数据库服务器要多少个连接-->
    <property name="acquireIncrement">5</property>
    <!--初始化连接数-->
    <property name="initialPoolSize">5</property>
    <!--最小连接数-->
    <property name="minPoolSize">5</property>
    
    <!--最大连接数-->
    <property name="maxPoolSize">10</property>
    <!--数据库连接池能维护的最多的Statement 的数量-->
    <property name="maxStatements">20</property>
    <!--每个数据库连接可以创建多少个Statement -->
    <property name="maxStatementsPerConnection">5</property>
    </named-config>
    </c3p0-config>

     

     

    //com.mchange.v2.c3p0.ComboPooledDataSource
    创建数据源:(由C3P0实现了SQL接口,实现的内容就是我们刚才包含的配置信息)
    DataSource dataSource = new ComboPooledDataSource("dbInfo");
    获取连接:
    Connection conn = dataSource.getConnection();

     

    如果出现The reference to entity "characterEncoding" must end with the ';' delimiter这样的错误:

    原因:

    数据源配置时加上编码转换格式后出问题了:

    The reference to entity "characterEncoding" must end with the ';' delimiter

    这个错误就是 配置文件xml中设置数据源链接URL的问题  

     

    原来:

    jdbc:mysql://localhost:3306/dbName?useUnicode=true&characterEncoding=UTF-8

    修改后:

    jdbc:mysql://localhost:3306/dbName?useUnicode=true&amp;characterEncoding=UTF-8

     

    这大概是由xml文件中的编码规则决定要这么变换。在xml文件中有以下几类字符要进行转义替换:

     

    &lt; < 小于号
    &gt; > 大于号
    &amp; &
    &apos; ' 单引号
    &quot; " 双引号
  • 相关阅读:
    EasyUI treegrid 加载checked
    html 文字垂直居中
    SQLSERVER 2008 查询数据字段名类型
    EasyUI TreeJson
    win7 网站发布备注
    LVS Nginx HAProxy 优缺点
    快速安装laravel和依赖
    Whoops, looks like something went wrong
    View.findViewById()和Activity.findViewById()区别
    ListView下拉刷新,上拉自动加载更多
  • 原文地址:https://www.cnblogs.com/0xcafedaddy/p/4733533.html
Copyright © 2011-2022 走看看