|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
805, 2021 9:26:41 下午 com.mchange.v2.log.MLog 
信息: MLog clients using java 1.4+ standard logging.
805, 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]
805, 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 李白 253000.0 2017-10-01

Process finished with exit code 0

 
 
 
 
 
 
 
 
 

Walter 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

 

 

posted on   yanqi_vip  阅读(23)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示