|NO.Z.00099|——————————|BigDataEnd|——|Java&MySQL.数据库连接池和DBUtils.V08|——|MySQL.v08|C3P0连接池工具测试|
一、C3P0连接池工具类测试
### --- 测试工具类
——>        需求: 查询姓名为 李白的员工信息public class TestC3P0 {
    //需求 查询姓名为李白的 记录
    public static void main(String[] args) throws SQLException {
        //1.获取连接
        Connection con = C3P0Utils.getConnection();
        //2.获取预处理对象
        String sql = "select * from employee where ename = ?";
        PreparedStatement ps = con.prepareStatement(sql);
        //3.设置占位符的值
        ps.setString(1,"李白");
        ResultSet resultSet = ps.executeQuery();
        //4.处理结果集
        while(resultSet.next()){
            int eid = resultSet.getInt("eid");
            String ename = resultSet.getString("ename");
            int age = resultSet.getInt("age");
            String sex = resultSet.getString("sex");
            double salary = resultSet.getDouble("salary");
            Date date = resultSet.getDate("empdate");
            
            System.out.println(eid +" " + ename + " " + age +" " + sex +" " + salary +" "+date);
        }
        
        //5.释放资源
        C3P0Utils.close(con,ps,resultSet);
    }
}       二、常见配置

三、sql语句
package com.yanqi.testpool;
        import com.yanqi.utils.C3P0Utils;
        import java.sql.*;
public class TestC3P0 {
    //需求 查询姓名为李白的 记录
    public static void main(String[] args) throws SQLException {
        //1.获取连接
        Connection con = C3P0Utils.getConnection();
        //2.获取预处理对象
        String sql = "select * from employee where ename = ?";
        PreparedStatement ps = con.prepareStatement(sql);
        //3.设置占位符的值
        ps.setString(1,"李白");
        ResultSet resultSet = ps.executeQuery();
        //4.处理结果集
        while(resultSet.next()){
            int eid = resultSet.getInt("eid");
            String ename = resultSet.getString("ename");
            int age = resultSet.getInt("age");
            String sex = resultSet.getString("sex");
            double salary = resultSet.getDouble("salary");
            Date date = resultSet.getDate("empdate");
            System.out.println(eid +" " + ename + " " + age +" " + sex +" " + salary +" " +date);
        }
        //5.释放资源
        C3P0Utils.close(con,ps,resultSet);
    }
}四、打印输出
D:\JAVA\jdk-11.0.2\bin\java.exe "-javaagent:D:\IntelliJIDEA\IntelliJ IDEA 2019.3.3\lib\idea_rt.jar=62467:D:\IntelliJIDEA\IntelliJ IDEA 2019.3.3\bin" -Dfile.encoding=UTF-8 -classpath "E:\NO.Z.10000——javaproject\NO.H.00002.mysql\mysql\out\production\mysql.jdbc_task06;F:\NO.Z.02000——soft——IT.实验\20210801——Hadoop\20210801.2——Hadoop——第二阶段——预科班\预科班第二阶段模块一\05 任务五 (JDBC)\03_软件\myJar\dom4j-1.6.1.jar;F:\NO.Z.02000——soft——IT.实验\20210801——Hadoop\20210801.2——Hadoop——第二阶段——预科班\预科班第二阶段模块一\05 任务五 (JDBC)\03_软件\myJar\druid-1.0.9.jar;F:\NO.Z.02000——soft——IT.实验\20210801——Hadoop\20210801.2——Hadoop——第二阶段——预科班\预科班第二阶段模块一\05 任务五 (JDBC)\03_软件\myJar\c3p0-0.9.5.2.jar;F:\NO.Z.02000——soft——IT.实验\20210801——Hadoop\20210801.2——Hadoop——第二阶段——预科班\预科班第二阶段模块一\05 任务五 (JDBC)\03_软件\myJar\commons-dbcp-1.4.jar;F:\NO.Z.02000——soft——IT.实验\20210801——Hadoop\20210801.2——Hadoop——第二阶段——预科班\预科班第二阶段模块一\05 任务五 (JDBC)\03_软件\myJar\jaxen-1.1-beta-6.jar;F:\NO.Z.02000——soft——IT.实验\20210801——Hadoop\20210801.2——Hadoop——第二阶段——预科班\预科班第二阶段模块一\05 任务五 (JDBC)\03_软件\myJar\commons-pool-1.5.6.jar;F:\NO.Z.02000——soft——IT.实验\20210801——Hadoop\20210801.2——Hadoop——第二阶段——预科班\预科班第二阶段模块一\05 任务五 (JDBC)\03_软件\myJar\commons-dbutils-1.6.jar;F:\NO.Z.02000——soft——IT.实验\20210801——Hadoop\20210801.2——Hadoop——第二阶段——预科班\预科班第二阶段模块一\05 任务五 (JDBC)\03_软件\myJar\mchange-commons-java-0.2.12.jar;F:\NO.Z.02000——soft——IT.实验\20210801——Hadoop\20210801.2——Hadoop——第二阶段——预科班\预科班第二阶段模块一\05 任务五 (JDBC)\03_软件\myJar\mysql-connector-java-5.1.37-bin.jar" com.yanqi.testpool.TestC3P0
8月 05, 2021 9:26:41 下午 com.mchange.v2.log.MLog 
信息: MLog clients using java 1.4+ standard logging.
8月 05, 2021 9:26:44 下午 com.mchange.v2.c3p0.C3P0Registry 
信息: Initializing c3p0-0.9.5.2 [built 08-December-2015 22:06:04 -0800; debug? true; trace: 10]
8月 05, 2021 9:26:45 下午 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource 
信息: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> mysql, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 1hge135aj68oxg021fr0u|41ee392b, idleConnectionTestPeriod -> 0, initialPoolSize -> 10, jdbcUrl -> jdbc:mysql://localhost:3306/db5?characterEncoding=UTF-8, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 30, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 100, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 10, numHelperThreads -> 3, preferredTestQuery -> null, privilegeSpawnedThreads -> false, properties -> {password=******, user=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
4 李白 25 男 3000.0 2017-10-01
Process finished with exit code 0Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor
 
                    
                 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号