zoukankan      html  css  js  c++  java
  • c3p0使用

    c3p0-config.xml

    <?xml version="1.0" encoding="UTF-8"?>
    
    <c3p0-config>
    
        <named-config name="mvc">
            <property name="user">root</property>
            <property name="password">root</property>
            <property name="driverClass">com.mysql.jdbc.Driver</property>
            <property name="jdbcUrl">jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&amp;characterEncoding=UTF8</property>
            <!-- ?useUnicode=true&amp;characterEncoding=UTF8 -->
            <property name="acquireIncrement">2</property>
            <property name="initialPoolSize">5</property>
            <property name="minPoolSize">5</property>
            <property name="maxPoolSize">10</property>
    
            <property name="maxStatements">20</property>
            <property name="maxStatementsPerConnection">5</property>
        </named-config>
    </c3p0-config>

    JdbcUtils

    package Utils;
    
    import java.sql.Connection;
    import java.sql.SQLException;
    
    import javax.sql.DataSource;
    
    import com.mchange.v2.c3p0.ComboPooledDataSource;
    
    public class JdbcUtil {
        
        public static void reaseConnection(Connection connection) {
            try {
                if(connection!=null){
                    connection.close();
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        private static DataSource dataSource = null;
        static{
            dataSource = new ComboPooledDataSource("mvc");
        }
        
        public static DataSource getDataSource(){
            return dataSource;
        }
        
        public static Connection getConnection(){
            try {
                return dataSource.getConnection();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                //e.printStackTrace();
                System.out.println("连接失败");
            }
            return null;
            
        }
    }
  • 相关阅读:
    Promise小结
    Jquery 一次处理多个ajax请求的代码
    for of 与 for in的区别
    三级联动效果
    最好的拖拽js
    Unicode转义(uXXXX)的编码和解码
    禁止遮罩层以下屏幕滑动
    director.js:客户端的路由---简明中文教程
    通过CSS的border绘制三角形
    概率图模型(PGM)学习笔记(四)-贝叶斯网络-伯努利贝叶斯-多项式贝叶斯
  • 原文地址:https://www.cnblogs.com/lusufei/p/7155273.html
Copyright © 2011-2022 走看看