CC00099.bigdatajava——|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 0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yanqi_vip

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值