zoukankan      html  css  js  c++  java
  • c3p0连接数据库

    <?xml version="1.0" encoding="UTF-8"?>
    <c3p0-config>
        <default-config>
            <!-- 最多可以创建多少个statement -->
            <!-- 最多可以创建多少个statement -->
            <property name="maxStatements">50</property>
            <!-- 最多有多少个连接 -->
            <property name="maxPoolSize">4</property>
            <property name="initialPoolSize">2</property>
            <property name="acquireIncrement">2</property>
            <property name="minPoolSize">2</property>
            <!-- 连接的超时间 -->
            <property name="checkoutTimeout">3000</property>
            <property name="driverClass">com.mysql.jdbc.Driver</property>
            <property name="jdbcUrl">jdbc:mysql:///abc
            </property>
            <property name="user">root</property>
            <property name="password">1234</property>
        </default-config>
    
        <!-- 配置其他的连接,用户的其他配置可以有多个 -->
        
        
        <named-config name="jtedu">
        
        <property name="maxStatements">50</property>
            <!-- 最多有多少个连接 -->
            <property name="maxPoolSize">4</property>
            <property name="initialPoolSize">2</property>
            <property name="acquireIncrement">2</property>
            <property name="minPoolSize">2</property>
            <!-- 连接的超时间 -->
            <property name="checkoutTimeout">3000</property>
            <property name="driverClass">com.mysql.jdbc.Driver</property>
            <property name="jdbcUrl">jdbc:mysql:///abc
            </property>
            <property name="user">root</property>
            <property name="password">1234</property>
         </named-config> 
    </c3p0-config>
    package c3p0连接池;
    
    import java.sql.Connection;
    
    import javax.sql.DataSource;
    
    import com.mchange.v2.c3p0.ComboPooledDataSource;
    
    public class c3p0Utiles {
        
    //    public static void main(String[] args) {
    //        System.err.println(c3p0Utiles.getCon());
    //        
    //    }
    
        private static DataSource ds;
        static {
    //默认配置  
    ds
    = new ComboPooledDataSource();
    //指定配置
    //ds=new ComboPooledDataSource("jteud"); }
    public static DataSource getDs() { return ds; } public static Connection getCon() { Connection con = null; try { con = ds.getConnection(); } catch (Exception e) { e.printStackTrace(); } return con; } }
  • 相关阅读:
    use evolation+mapi with exhange mode
    python open file mode description
    5 reasons why you should learn python programming
    文本从尾到头输出
    安装部署lamp,来测试rediect
    python for ,loop ,else condition test
    python logging usage
    去除重复行
    [WTL]WTL for MFC Programming实践篇 一个自定义ComboBox的移植过程
    subsonic已死,db4o将死
  • 原文地址:https://www.cnblogs.com/xiaweifeng/p/3704410.html
Copyright © 2011-2022 走看看