zoukankan      html  css  js  c++  java
  • c3p0 获取数据源

    getDataSourcec3p0Resource
        private static void f3Resource() throws Exception {
            Connection conn = getDataSourcec3p0Resource().getConnection();
            int res = executeUpdate(conn);
            System.out.println(res);
        }
    
        private static DataSource getDataSourcec3p0Resource() throws Exception {
            ComboPooledDataSource c3p0 = new ComboPooledDataSource("test");
            return  c3p0;
        }
    
        private static void f3() throws Exception {
            Connection conn = getDataSourceC3p0().getConnection();
            int res = executeUpdate(conn);
            System.out.println(res);
        }
    
        public static DataSource getDataSourceC3p0() throws Exception {
            ComboPooledDataSource c3p0 = new ComboPooledDataSource();
            c3p0.setDriverClass("com.mysql.jdbc.Driver");
            c3p0.setJdbcUrl("jdbc:mysql://localhost:3306/jdbc");
            c3p0.setUser("root");
            c3p0.setPassword("root1010");
            return c3p0;
        }
        
        private static int executeUpdate(Connection conn) {
            String sql = "UPDATE `user` set money=666 where id=?";
            Object[] objs = new Object[]{"1"};
            return JdbcUtils.executeUpdate(conn, sql, objs);
        }

    11

    <?xml version="1.0" encoding="UTF-8"?>
    <c3p0-config>
        <!-- 默认配置,如果没有指定则使用这个配置 -->
        <default-config>
            <property name="user">root</property>
            <property name="password">xxx</property>
            <property name="jdbcUrl">jdbc:mysql://localhost:3306/jdbc</property>
            <property name="driverClass">com.mysql.jdbc.Driver</property>
            <property name="checkoutTimeout">30000</property>
            <property name="idleConnectionTestPeriod">30</property>
            <property name="initialPoolSize">3</property>
            <property name="maxIdleTime">30</property>
            <property name="maxPoolSize">100</property>
            <property name="minPoolSize">2</property>
            <property name="maxStatements">200</property>
        </default-config>
        <!-- 命名的配置,可以通过方法调用实现 -->
        <named-config name="test">
            <property name="user">root</property>
            <property name="password">xxx</property>
            <property name="jdbcUrl">jdbc:mysql://localhost:3306/jdbc</property>
            <property name="driverClass">com.mysql.jdbc.Driver</property>
            <!-- 如果池中数据连接不够时一次增长多少个 -->
            <property name="acquireIncrement">5</property>
            <!-- 初始化数据库连接池时连接的数量 -->
            <property name="initialPoolSize">20</property>
            <!-- 数据库连接池中的最大的数据库连接数 -->
            <property name="maxPoolSize">25</property>
            <!-- 数据库连接池中的最小的数据库连接数 -->
            <property name="minPoolSize">5</property>
        </named-config>
    </c3p0-config>
  • 相关阅读:
    docker是PaaS,与openstack是IaaS的关系
    nuget安装.net standard
    GitHub sync the original repository by pull request
    Is there a way to include commas in CSV columns without breaking the formatting?
    How to determine why visual studio might be skipping projects when building a solution
    IHttpHandler vs IHttpModule
    .NET 3.0 SDK Projects not Loading
    Microsoft Edge version
    Microsoft Edge High CPU and Memory
    Google Analytics
  • 原文地址:https://www.cnblogs.com/kikyoqiang/p/11784404.html
Copyright © 2011-2022 走看看