首页 > 数据库 >mysql-connector-java版本大于5,项目启动连接数据库报错

mysql-connector-java版本大于5,项目启动连接数据库报错

时间:2023-03-12 14:23:38浏览次数:50  
标签:8.0 java 17 connector 报错 mysql com

项目启动连接数据库报错如下

2023-02-08 22:44:23.491 ERROR 23596 --- [reate-951000054] com.alibaba.druid.pool.DruidDataSource   : create connection SQLException, url: jdbc:mysql://192.168.56.10:3306/gulimall_pms, errorCode 0, state 08S01

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
	at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:827) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:447) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:237) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1570) ~[druid-1.1.13.jar:1.1.13]
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1636) ~[druid-1.1.13.jar:1.1.13]
	at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2550) ~[druid-1.1.13.jar:1.1.13]
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_321]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_321]
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_321]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_321]
	at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:340) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	at com.mysql.cj.protocol.a.NativeAuthenticationProvider.negotiateSSLConnection(NativeAuthenticationProvider.java:777) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:486) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:202) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1348) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	at com.mysql.cj.NativeSession.connect(NativeSession.java:163) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:947) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:817) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	... 6 common frames omitted
Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
	at sun.security.ssl.HandshakeContext.<init>(HandshakeContext.java:171) ~[na:1.8.0_321]
	at sun.security.ssl.ClientHandshakeContext.<init>(ClientHandshakeContext.java:106) ~[na:1.8.0_321]
	at sun.security.ssl.TransportContext.kickstart(TransportContext.java:237) ~[na:1.8.0_321]
	at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:405) ~[na:1.8.0_321]
	at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:384) ~[na:1.8.0_321]
	at com.mysql.cj.protocol.ExportControlled.performTlsHandshake(ExportControlled.java:316) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	at com.mysql.cj.protocol.StandardSocketFactory.performTlsHandshake(StandardSocketFactory.java:188) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	at com.mysql.cj.protocol.a.NativeSocketConnection.performTlsHandshake(NativeSocketConnection.java:99) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:331) ~[mysql-connector-java-8.0.17.jar:8.0.17]
	... 13 common frames omitted

解决如下

若mysql-connector-java > 5 例如:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.17</version>
</dependency>

需要在数据库连接后加上?useSSL=false

url: jdbc:mysql://192.168.56.10:3306/gulimall_pms?useSSL=false

如有错漏之处,敬请指正。

标签:8.0,java,17,connector,报错,mysql,com
From: https://www.cnblogs.com/LucasMeng/p/17208099.html

相关文章

  • Java面向对象的三大特性:封装、继承、多态
    1、封装  封装的特点:高内聚,低耦合,说白了就好比电视机,它把里面的线路都给隐藏了,只留给我几个接口供我们使用。高类聚就是类的内部数据细节由自己来完成,不允许外部干涉,低......
  • Java应用【XVIII】在 Java 中使用JUnit5进行单元测试和自动化测试
    一、前言单元测试和自动化测试是现代软件开发过程中必不可少的环节,可以提高代码质量和开发效率。JUnit5是Java中流行的单元测试框架,本文将介绍如何在Java中使用JUnit5进行单......
  • Javadoc工具的使用
    Java提供了Javadoc工具,通过这个工具可以使你编写的代码生成一份API文档,前提是你已经为你的程序提供了文档注释。下面Javadoc工具使用的步骤:在你的代码中添加文档注释pub......
  • Java 剑指offer(16) 打印1到最大的n位数
    题目输入数字n,按顺序打印出从1最大的n位十进制数。比如输入3,则打印出1、2、3一直到最大的3位数即999。思路陷阱:n过大时是大数问题,不能简单用int或者long数据输出,需要采......
  • Java中的保留字
    下面是Java中的保留字及其含义:保留字含义abstract抽象类或抽象方法assert断言条件为真boolean布尔类型break跳出循环或switch语句byte8位带符号整......
  • Java 建造者模式/链式调用 简单Demo
    最近,公司同事要求我给他们讲一下RxJava,为了更清晰的说明其架构,.简单写了一个链式调用的小Demo,分享给大家/**作者:赵星海(CSDN-深海呐)*时间:2019年3月19日16:56:32*......
  • Java 关于单例模式(懒汉式与饿汉式的区别)
             Java关于单例模式(懒汉式与饿汉式的区别)简单说下两个单例模式的不同点懒汉式:1.内部对象非final类型2.线程安全3.用到特定方法的时候才会实例......
  • Java 一行代码判断String字符串是否为纯符号
                 一行代码判断String字符串是否为纯符号 最近项目中新加的需求我感觉我的构思很好,分享给大家原理:1.将String去除前后空格2.将Str......
  • Java 判断String字符串是否是中文
    判断String字符串是否是中文Stringstring;//需要判断的内容if(string.matches("[\u4E00-\u9FA5]+")){ToastUtils.Toast(Activity_authentication.this,"内容是中文")......
  • Java 自定义提取字符串中的某一段字符
                     自定义String过滤举例:Strings="dsadsada<@#$@#$>啦啦啦123123<&*&*&*>"要去除所有尖括号里的内容得到结果 "dsa......