SQLyog基础操作(十六)-IDEA连接数据库、IDEA进行数据库事务操作、数据库连接池(开源数据库(DBCP、C3P0))

10.8 使用IDEA连接数据库

1.选择Database,点击“+”,选择Data Source,选择MySQL

2.出现新页面后,在Drivers选项卡下,向下滑,找到MySQL

选择MySQL,加载数据库驱动,Apply,OK

切换到上面的MySQL-@localhost进行数据库连接,输入用户名、密码,进行测试连接,测试成功后,Apply,OK

连接成功

连接成功后的数据信息

切换数据库:选择设置,点击当前数据库下的Schemes,选择要使用的数据库,Apply,OK

切换成功

双击表名称,查看表内容

修改表内容:在表格数据上直接修改,修改完后点击“含有DB的向上箭头”,完成数据的更新

IDEA中代码执行:

打开控制台,可以在默认打开的控制台中直接编写,此处默认的是console[MySQL-@localhost]

编写SQL代码:

 /*创建账户表*/
 CREATE TABLE `account`(
     `id` INT PRIMARY KEY AUTO_INCREMENT,
     `name` VARCHAR(40),
     `money` FLOAT
 );
 
 /*插入测试数据*/
 INSERT INTO `account`(`name`,`money`) VALUES('A',1000);
 INSERT INTO `account`(`name`,`money`) VALUES('B',1000);
 INSERT INTO `account`(`name`,`money`) VALUES('C',1000);

输出结果:

10.9 使用IDEA进行数据库事务操作

代码实现:

  1. 开启事务

  2. 一组业务执行完毕后,提交事务

  3. 可以在catch语句中显式的定义回滚语句,但默认失败就会回滚

测试代码

 package com.study.lesson;
 
 import utils.JdbcUtils;
 
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
 /**
  * 事务
  */
 public class JdbcTransaction {
     public static void main(String[] args) {
         //声明对象,扩大作用范围
         Connection cn = null;
         PreparedStatement ps = null;
         ResultSet rs = null;
 
         try {
             //连接数据库
             cn = JdbcUtils.getConnection();
 
             //开启事务
             cn.setAutoCommit(false);
 
             //sql语句
             String sql1 = "UPDATE `account` SET `money` = `money` - 100 WHERE `id` = 1";
             //预编译sql语句
             ps = cn.prepareStatement(sql1);
             //执行sql语句
             ps.executeUpdate();
 
             //int i = 1/0;//一定不成立的语句,被除数不能为零,这条语句不会编译报错,在运行时会报错
 
             String sql2 = "UPDATE `account` SET `money` = `money` + 100 WHERE `id` = 2";
             ps = cn.prepareStatement(sql2);
             ps.executeUpdate();
 
             //业务完毕,提交事务
             cn.commit();
             System.out.println("成功!");
        } catch (SQLException e) {
             //如果失败,则回滚事务
             try {
                 cn.rollback();
            } catch (SQLException e1) {
                 e1.printStackTrace();
            }
             e.printStackTrace();
        } catch(Exception e){
             e.printStackTrace();
        } finally {
             JdbcUtils.release(cn,ps,null);
        }
    }
 }
 

输出结果:

(1)执行成功

  控制台输出:成功!

  IDEA和SQLyog均可查看最终结果(两者一致):

(2)执行失败:报错,回滚

  控制台输出:java.lang.ArithmeticException: / by zero at com.study.lesson.JdbcTransaction.main(JdbcTransaction.java:31)

  IDEA和SQLyog均可查看最终结果(两者一致),无变化,与上面结果一致!

10.10 数据库连接池

数据库操作流程:数据库连接---执行完毕---释放连接资源,其中,从连接到释放,十分浪费系统资源,引入池化技术。

池化技术:准备一些预先的资源,过来就直接连接预先准备好的。

基本参数

  • 常用连接数:10

  • 最小连接数:10

  • 最大连接数:15

  • 等待超时:100ms

编写连接池,实现一个接口DataSource,调用准备好的资源。

10.10.1 开源数据源(拿来直接用)

  使用了这些数据库连接池之后,我们在项目开发中就不需要编写连接数据库的代码了

10.10.2 DBCP

需要用到的jar包:commons-dbcp-1.4、commons-pool-1.6

下载地址

https://mvnrepository.com/artifact/commons-dbcp/commons-dbcp/1.4

https://mvnrepository.com/artifact/commons-pool/commons-pool/1.6

1.编写dbcpconfig.properties配置文件

 # 连接设置
 driverClassName=com.mysql.jdbc.Driver
 url = jdbc:mysql://localhost:3306/jdbcstudy?useUnicode=true&characterEncoding=utf8&useSSL=true
 username = root
 password = 123456
 
 # <!-- 初始化连接 -->
 initialSize=10
 
 # 最大连接数量
 maxActive=50
 
 # <!-- 最大空闲连接 -->
 maxIdle=20
 
 # <!-- 最小空闲连接 -->
 minIdle=5
 
 # <!-- 超时等待时间以毫秒为单位 6000毫秒/1000等于60秒 -->
 maxWait=60000
 # JDBC驱动建立连接时附带的连接属性属性的格式必须为这样:【属性名=property;】
 # 注意:user 与 password 两个属性会被明确地传递,因此这里不需要包含他们。
 connectionProperties=useUnicode=true;characterEncoding=utf8
 
 # 指定由连接池所创建的连接的自动提交(auto-commit)状态。
 defaultAutoCommit=true
 
 # driver default 指定由连接池所创建的连接的只读(read-only)状态。
  #如果没有设置该值,则“setReadOnly”方法将不被调用。(某些驱动并不支持只读模式,如:Informix)
 defaultReadOnly=
 
 # driver default 指定由连接池所创建的连接的事务级别(TransactionIsolation)。
 # 可用值为下列之一:(详情可见javadoc。)NONE,READ_UNCOMMITTED, READ_COMMITTED, REPEATABLE_READ, SERIALIZABLE
 defaultTransactionIsolation=READ_COMMITTED

2.新建utils包,包下新建JdbcUtils_DBCP.java,用于从dbcpconfig.properties文件中读取文件资源、加载驱动、获取连接、释放连接资源等。

 package com.study.lesson.utils;
 
 import org.apache.commons.dbcp.BasicDataSourceFactory;
 import javax.sql.DataSource;
 import java.io.InputStream;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Properties;
 
 /**
  * 用于加载dbcpconfig.properties文件资源、加载驱动、获取连接、释放连接资源等
  */
 public class JdbcUtils_DBCP {
     //声明DataSource对象,扩大作用范围
     private static DataSource dataSource = null;
     static {
         try{
             //加载资源
             InputStream in = JdbcUtils_DBCP.class.getClassLoader().getResourceAsStream("dbcpconfig.properties");
 
             //获取资源
             Properties properties = new Properties();
             properties.load(in);
 
             //创建数据源 工厂模式--->创建
             dataSource = BasicDataSourceFactory.createDataSource(properties);
 
        }  catch(Exception e){
             e.printStackTrace();
        }
    }
 
     /**
      * 获取连接
      * @return
      * @throws SQLException
      */
     public static Connection getConnection() throws SQLException{
         return dataSource.getConnection();//从数据源中获取连接
    }
 
     /**
      * 释放连接资源
      * @param connection
      * @param statement
      * @param resultSet
      */
     public static void release(Connection connection, Statement statement, ResultSet resultSet){
         //关闭的顺序依次为resultSet、statement、connection
         if(resultSet!=null){
             try {
                 resultSet.close();
            } catch (SQLException e) {
                 e.printStackTrace();
            } catch(Exception e){
                 e.printStackTrace();
            }
        }
         if(statement!=null){
             try {
                 statement.close();
            } catch (SQLException e) {
                 e.printStackTrace();
            } catch(Exception e){
                 e.printStackTrace();
            }
        }
         if(connection!=null){
             try {
                 connection.close();
            } catch (SQLException e) {
                 e.printStackTrace();
            } catch(Exception e){
                 e.printStackTrace();
            }
        }
    }
 }
 

3.测试:以insert为例

 package com.study.lesson;
 
 import com.study.lesson.utils.JdbcUtils_DBCP;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
 
 /**
  * 基于DBCP测试insert
  */
 public class TestDBCP {
     public static void main(String[] args) {
         //声明对象,扩大作用范围
         Connection cn = null;
         PreparedStatement ps = null;
         try {
             //连接驱动,获取数据库
             cn= JdbcUtils_DBCP.getConnection();
 
             //使用?占位符代替参数
             String sql = "INSERT INTO `users`(`id`,`name`,`password`,`email`,`birthday`)" +
                     "VALUES(?,?,?,?,?)";
 
             //预编译SQL,先写sql,然后不执行
             ps = cn.prepareStatement(sql);
 
             //手动给参数赋值
             ps.setInt(1,5);
             ps.setString(2,"zhuangzhuang");
             ps.setString(3,"159357");
             ps.setString(4,"159357@qq.com");
             /**
              * 注意点:sql.Date 数据库
              *       util.Date Java
              *       new Date().getTime()获取时间戳
              */
             ps.setDate(5,new java.sql.Date(new java.util.Date().getTime()));
 
             //执行
             int i = ps.executeUpdate();
             if(i>0){
                 System.out.println("插入成功!");
            }
        } catch (SQLException e) {
             e.printStackTrace();
        } catch (Exception e){
             e.printStackTrace();
        } finally {
             JdbcUtils_DBCP.release(cn,ps,null);
        }
    }
 }
 

输出结果:插入成功!

        在IDEA和SQLyog数据库都能查看相应插入数据结果。

10.10.2 C3P0

需要的jar包:c3p0-0.9.5.5、mchange-commons-java-0.2.19

下载地址

https://mvnrepository.com/artifact/com.mchange/c3p0/0.9.5.5

https://mvnrepository.com/artifact/com.mchange/mchange-commons-java/0.2.19

1.编写C3P0配置文件c3p0-config.xml

 <?xml version="1.0" encoding="UTF-8"?>
 <c3p0-config>
     <!--
     c3p0的缺省(默认)配置
     如果在代码中ComboPooledDataSource ds=new ComboPooledDataSource();这样写就表示使用的是c3p0的缺省(默认)
     -->
     <default-config>
         <property name="driverClass">com.mysql.jdbc.Driver</property>
         <property name="jdbcUrl">jdbc:mysql://localhost:3306/jdbcstudy?userUnicode=true&amp;characterEncoding=utf8&amp;uesSSL=true&amp;serverTimezone=UTC</property>
         <property name="user">root</property>
         <property name="password">123456</property>
 
         <property name="acquiredIncrement">5</property>
         <property name="initialPoolSize">10</property>
         <property name="minPoolSize">5</property>
         <property name="maxPoolSize">20</property>
     </default-config>
 
     <!--
     c3p0的命名配置
     如果在代码中ComboPooledDataSource ds=new ComboPooledDataSource(MySQL);这样写就表示使用的是mysql的缺省(默认)
     -->
     <named-config name="MySQL">
     <property name="driverClass">com.mysql.jdbc.Driver</property>
     <property name="jdbcUrl">jdbc:mysql://localhost:3306/jdbcstudy?userUnicode=true&amp;characterEncoding=utf8&amp;uesSSL=true&amp;serverTimezone=UTC</property>
     <property name="user">root</property>
     <property name="password">123456</property>
 
     <property name="acquiredIncrement">5</property>
     <property name="initialPoolSize">10</property>
     <property name="minPoolSize">5</property>
     <property name="maxPoolSize">20</property>
     </named-config>
 </c3p0-config>

2.在utils包下新建JdbcUtils_C3P0.java,用于加载c3p0-config.xml文件资源、加载驱动、获取连接、释放连接资源等

 package com.study.lesson.utils;
 
 import com.mchange.v2.c3p0.ComboPooledDataSource;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 
 /**
  * 用于加载c3p0-config.xml文件资源、加载驱动、获取连接、释放连接资源等
  */
 public class JdbcUtils_C3P0 {
     //声明DataSource对象,扩大作用范围
     private static ComboPooledDataSource dataSource = null;
     static {
         try{
             //代码版配置
 //           dataSource = new ComboPooledDataSource();
 //           dataSource.setDriverClass();
 //           dataSource.setJdbcUrl();
 //           dataSource.setUser();
 //           dataSource.setPassword();
 //
 //           dataSource.setMaxPoolSize();
 //           dataSource.setMinPoolSize();
 
             //创建数据源 工厂模式--->创建
             dataSource = new ComboPooledDataSource("MySQL");//配置文件写法,此处使用默认配置好的MySQL数据库,还可以在配置文件中配置其他的数据库进行使用
 
        }  catch(Exception e){
             e.printStackTrace();
        }
    }
 
     /**
      * 获取连接
      * @return
      * @throws SQLException
      */
     public static Connection getConnection() throws SQLException{
         return dataSource.getConnection();//从数据源中获取连接
    }
 
     /**
      * 释放连接资源
      * @param connection
      * @param statement
      * @param resultSet
      */
     public static void release(Connection connection, Statement statement, ResultSet resultSet){
         //关闭的顺序依次为resultSet、statement、connection
         if(resultSet!=null){
             try {
                 resultSet.close();
            } catch (SQLException e) {
                 e.printStackTrace();
            } catch(Exception e){
                 e.printStackTrace();
            }
        }
         if(statement!=null){
             try {
                 statement.close();
            } catch (SQLException e) {
                 e.printStackTrace();
            } catch(Exception e){
                 e.printStackTrace();
            }
        }
         if(connection!=null){
             try {
                 connection.close();
            } catch (SQLException e) {
                 e.printStackTrace();
            } catch(Exception e){
                 e.printStackTrace();
            }
        }
    }
 }
 

3.测试:以insert为例

 package com.study.lesson;
 
 import com.study.lesson.utils.JdbcUtils_C3P0;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
 
 /**
  * 基于C3P0测试insert
  */
 public class TestC3P0 {
     public static void main(String[] args) {
         //声明对象,扩大作用范围
         Connection cn = null;
         PreparedStatement ps = null;
         try {
             //连接驱动,获取数据库
             cn= JdbcUtils_C3P0.getConnection();//原来是自己实现的,现在用别人实现的
 
             //使用?占位符代替参数
             String sql = "INSERT INTO `users`(`id`,`name`,`password`,`email`,`birthday`)" +
                     "VALUES(?,?,?,?,?)";
 
             //预编译SQL,先写sql,然后不执行
             ps = cn.prepareStatement(sql);
 
             //手动给参数赋值
             ps.setInt(1,7);
             ps.setString(2,"ihgfhjh");
             ps.setString(3,"962415");
             ps.setString(4,"98432651525@qq.com");
             /**
              * 注意点:sql.Date 数据库
              *       util.Date Java
              *       new Date().getTime()获取时间戳
              */
             ps.setDate(5,new java.sql.Date(new java.util.Date().getTime()));
 
             //执行
             int i = ps.executeUpdate();
             if(i>0){
                 System.out.println("插入成功!");
            }
        } catch (SQLException e) {
             e.printStackTrace();
        } catch (Exception e){
             e.printStackTrace();
        } finally {
             JdbcUtils_C3P0.release(cn,ps,null);
        }
    }
 }
 
 

输出结果:里面包含日志

 D:\Software_Development\JDK\bin\java.exe "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2020.1\lib\idea_rt.jar=52802:C:\Program Files\JetBrains\IntelliJ IDEA 2020.1\bin" -Dfile.encoding=UTF-8 -classpath D:\Software_Development\JDK\jre\lib\charsets.jar;D:\Software_Development\JDK\jre\lib\deploy.jar;D:\Software_Development\JDK\jre\lib\ext\access-bridge-64.jar;D:\Software_Development\JDK\jre\lib\ext\cldrdata.jar;D:\Software_Development\JDK\jre\lib\ext\dnsns.jar;D:\Software_Development\JDK\jre\lib\ext\jaccess.jar;D:\Software_Development\JDK\jre\lib\ext\jfxrt.jar;D:\Software_Development\JDK\jre\lib\ext\localedata.jar;D:\Software_Development\JDK\jre\lib\ext\nashorn.jar;D:\Software_Development\JDK\jre\lib\ext\sunec.jar;D:\Software_Development\JDK\jre\lib\ext\sunjce_provider.jar;D:\Software_Development\JDK\jre\lib\ext\sunmscapi.jar;D:\Software_Development\JDK\jre\lib\ext\sunpkcs11.jar;D:\Software_Development\JDK\jre\lib\ext\zipfs.jar;D:\Software_Development\JDK\jre\lib\javaws.jar;D:\Software_Development\JDK\jre\lib\jce.jar;D:\Software_Development\JDK\jre\lib\jfr.jar;D:\Software_Development\JDK\jre\lib\jfxswt.jar;D:\Software_Development\JDK\jre\lib\jsse.jar;D:\Software_Development\JDK\jre\lib\management-agent.jar;D:\Software_Development\JDK\jre\lib\plugin.jar;D:\Software_Development\JDK\jre\lib\resources.jar;D:\Software_Development\JDK\jre\lib\rt.jar;D:\Software_Development\IDEA_code\API\JDBC\out\production\JDBC;D:\Software_Development\IDEA_code\API\JDBC\lib\c3p0-0.9.5.5.jar;D:\Software_Development\IDEA_code\API\JDBC\lib\commons-dbcp-1.4.jar;D:\Software_Development\IDEA_code\API\JDBC\lib\commons-pool-1.6.jar;D:\Software_Development\IDEA_code\API\JDBC\lib\mchange-commons-java-0.2.19.jar;D:\Software_Development\IDEA_code\API\JDBC\lib\mysql-connector-java-5.1.47.jar com.study.lesson.TestC3P0
 七月 15, 2021 3:58:04 下午 com.mchange.v2.log.MLog
 信息: MLog clients using java 1.4+ standard logging.
 七月 15, 2021 3:58:04 下午 com.mchange.v2.c3p0.cfg.C3P0Config
 警告: Unknown c3p0-config property: acquiredIncrement
 七月 15, 2021 3:58:04 下午 com.mchange.v2.c3p0.cfg.C3P0Config
 警告: Unknown c3p0-config property: acquiredIncrement
 七月 15, 2021 3:58:04 下午 com.mchange.v2.c3p0.C3P0Registry
 信息: Initializing c3p0-0.9.5.5 [built 11-December-2019 22:18:33 -0800; debug? true; trace: 10]
 七月 15, 2021 3:58:04 下午 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 -> 1hge9ivai1axth3zbtoahz|45283ce2, idleConnectionTestPeriod -> 0, initialPoolSize -> 10, jdbcUrl -> jdbc:mysql://localhost:3306/jdbcstudy?userUnicode=true&characterEncoding=utf8&uesSSL=true&serverTimezone=UTC, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 5, numHelperThreads -> 3, preferredTestQuery -> null, privilegeSpawnedThreads -> false, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
 Thu Jul 15 15:58:05 CST 2021 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
 Thu Jul 15 15:58:05 CST 2021 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
 Thu Jul 15 15:58:05 CST 2021 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. 
Thu Jul 15 15:58:05 CST 2021 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. 
Thu Jul 15 15:58:05 CST 2021 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. 
Thu Jul 15 15:58:05 CST 2021 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. 
Thu Jul 15 15:58:05 CST 2021 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. 
Thu Jul 15 15:58:05 CST 2021 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. 
Thu Jul 15 15:58:05 CST 2021 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. 
Thu Jul 15 15:58:05 CST 2021 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. 
插入成功! 
​ 
Process finished with exit code

  在IDEA和SQLyog数据库都能查看相应插入数据结果。

10.10.4 结论

  无论使用什么数据源,本质还是一样的,DataSource接口不会变,方法就不会变。

 

posted @ 2021-07-15 17:31  Coder_Cui  阅读(1485)  评论(0编辑  收藏  举报