The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received_我是一个快乐的javaer的博客-程序员秘密

关于版本比较新的数据库(Mysql8.0)连接的问题:

he 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:172)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:862)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:444)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:230)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:226)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at mysqlconnect.connect.main(connect.java:24)
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)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:59)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:103)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:149)
at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:165)
at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:355)
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.negotiateSSLConnection(NativeAuthenticationProvider.java:789)
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:499)
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:217)
at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1411)
at com.mysql.cj.NativeSession.connect(NativeSession.java:165)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:982)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:852)
... 6 more
Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
at sun.security.ssl.Handshaker.processLoop(Unknown Source)
at sun.security.ssl.Handshaker.process_record(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.mysql.cj.protocol.ExportControlled.performTlsHandshake(ExportControlled.java:213)
at com.mysql.cj.protocol.StandardSocketFactory.performTlsHandshake(StandardSocketFactory.java:206)
at com.mysql.cj.protocol.a.NativeSocketConnection.performTlsHandshake(NativeSocketConnection.java:99)
at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:350)
... 13 more
Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
at com.mysql.cj.protocol.ExportControlled$X509TrustManagerWrapper.checkServerTrusted(ExportControlled.java:280)
at sun.security.ssl.AbstractTrustManagerWrapper.checkServerTrusted(Unknown Source)
... 25 more
Caused by: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
at sun.security.provider.certpath.PKIXCertPathValidator.validate(Unknown Source)
at sun.security.provider.certpath.PKIXCertPathValidator.engineValidate(Unknown Source)
at java.security.cert.CertPathValidator.validate(Unknown Source)
at com.mysql.cj.protocol.ExportControlled$X509TrustManagerWrapper.checkServerTrusted(ExportControlled.java:273)
... 26 more
Exception in thread "main" java.lang.NullPointerException
at mysqlconnect.connect.main(connect.java:34)

网上说的什么修改的方法对我没有用

诸如此类:

1·修改my.ini bind-address = 127.0.0.1 为 bind-address = 0.0.0.0   使非本地网络可以访问数据库

2·检查防火墙是否有开放3306端口

3·网上广为流传的86400秒超时 回收机制 并不和我遇到的问题一致,这种问题是在程序运行过程中因为我们使用的连接池不知道连接被回收了所以报出的异常,解决方案可以是修改连接池配置或修改mysql空闲超时时间配置。

以上方法均没用,主要是mysql和驱动版本的问题

我的mysql是8.0,驱动也是8.x最新的;

Class.forName("com.mysql.cj.jdbc.Driver");

url = "jdbc:mysql://localhost:3306/jnditest?serverTimezone=GMT&useSSL=false";//数据库的路径

主要是红色字体方面,serverTimezone缺失是很容易从错误找出来的,但是重点是useSSL=false,这个从错误提示是看不出来的,它有个很重要的作用是使用JDBC跟你的数据库连接的时候,你的JDBC版本与MySQL版本不兼容,MySQL的版本更高一些,在连接语句后加上“useSSL=‘true’” ,就可以连接到数据库了。更高版本。但如果是兼容版本的话就会出错。

我试了改成true的确又出现了这个问题。

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/ponxbin/article/details/80608040

智能推荐

OpenGL的版本发展_此昵称已经存在吗的博客-程序员秘密

OpenGL ES1.2 什么是OpenGL ES图形系统     OpenGL ES是访问已经图形加速器的软件接口,大部分需要framebuffer. OpenGL ES1.1是基于OpenGL 1.5的,去掉了很多冗余和遗留的函数。它们之间的不同在文档Specification>>, common-lite是面向硬件上没有浮点运算的目标机,它的参数全是定点,common则还支持浮点参数

数值计算之 最小二乘法(1)最小二乘计算与线性方程_线性方程组最小二乘解目标函数_RuiH.AI的博客-程序员秘密

数值计算之 最小二乘法(1)最小二乘计算与矩阵前言最小二乘法与线性方程组最小二乘解与矩阵计算总结前言本篇开启一个非常重要的内容,最小二乘法。它在方程组求解、多视图几何计算、线性优化等方面具有广泛的应用。本节是最小二乘法的第一部分,将最小二乘与线性代数关联。最小二乘法与线性方程组最小二乘法的起源在数值计算拟合法中已经提到过,最小二乘法最早用于数据拟合:arg min⁡f(x)∑i=0n(f(xi)−yi)2\argmin_{f(x)} \sum_{i=0}^n (f(x_i)-y_i)^2f

第五章组件化开发方法_组件开发制度_weixin_44712739的博客-程序员秘密

一.实验目的1.掌握组件化开发的概念,了解CORBA模型及ORB机制;2.掌握CORBA组件编程方法。二、实验内容步骤:1.配制环境JDK环境。2.编写编译IDL接口。3.编写编译服务端程序。4.编写编译客户端程序。5.运行测试与调试。6.完成报告。题目1.Java版CORBA程序1——HelloWorld实现详解:1 编写IDL接口HelloWorld.idl:mod...

java版的selenium下载文件_如何使用Selenium Webdriver下载任何文件并将其保存到所需位置..._精灵之火的博客-程序员秘密

一种可能的解决方案是通过Selenium获取文件的URL,创建(非Selenium)连接,将Selenium的cookie复制到该连接(如果需要),然后下载文件。大多数语言都有用于执行HTTP请求的API(或库)。例如,要在Java中完成此操作,可以使用URL.openConnection():String link = linkElement.getAttribute("href");URL u...

OSDI文章分享,论文(Fast RDMA-based Ordered Key-Value Store using Remote Learned Cache)的结构化文摘_结构化文摘的博客-程序员秘密

Authors:Xingda Wei, Rong Chen, and Haibo Chen,Shanghai Jiao Tong UniversityAbstract:RDMA (Remote Direct Memory Access) has gained considerable interests in network-attached in-memory key-value stores. However, traversing the remote tree-based inde...

搭建个人深度学习工作站_熊猫小伙的博客-程序员秘密

搭建个人深度学习工作站文章目录搭建个人深度学习工作站1.购买之前- 具体配置- 其他升级了的内容:- GPU安装视频2. 搭建系统2.1 系统选择- `搭建系统`:ubuntu20.04- 如何安装ubuntu系统2.2 系统环境配置过程2.2.1 ubuntu常用工具安装(1) 服务器安装 ssh(2) 远程桌面工具(3) 内网穿透(4) 远程操作 &amp; 服务器监控(5) ubuntu便捷使用2.2.1 DL前置环境配置(1) driver-510.60 &amp; cuda 11.2 &amp;

随便推点

一文读懂Rust的async_rust async_一个不安分的程序员的博客-程序员秘密

因为这些运行时之间有很多`相通`的地方,熟悉了一个再去熟悉其它的就简单了。就像我们学习编程语言一样,学好学深一门编程语言,再去学习其它的语言就快了。不要一开始就几门语言一起学,这样很可能实际开发时这也不行那也不行换来换去还是不能开发出东西.

基于JQuery封装自定义美化的 select组件_jquery select组件_魔幻星辰的博客-程序员秘密

浏览器自带的select组件样式太丑,有时候想要一款自己满意的组件,不满意样式还可以自行修改;组件封装不是得多完美,适用才是最好的;select组件配套的CSS/* UI组件样式 *//* select */.stui_select {width: 100%;position: absolute;top: 0;left: 0;z-index: 10;}.stui_select h3 {line-height: 32px;}.stui_select dl{border: 1px solid #e

android 工业平板 编程,Android工业级平板电脑开发与应用_电竞GO的博客-程序员秘密

原标题:Android工业级平板电脑开发与应用一、Android工业级平板电脑开发引言:Android的开源使厂商无需自行研发OS,大大降低了研发、生产的成本,使得Android平板品牌如雨后春笋般爆发,山寨机厂商们似乎又找到了一丝希望。与此同时带来的是广大开发者的苦不堪言,各种神奇的小板儿考验着app的兼容性,各种定制的rom不经意间就让app崩溃,光是界面上的调整就已经够你喝一壶了。 二、An...

Spring Boot 精简使用教程_Andy_Li_的博客-程序员秘密

Spring Boot 使用教程前言目录前言本博客主要分享博主学习 Spring Boot 的过程,特别是学习的方式—— 查看官方文档的正确姿势(如果觉得有问题欢迎小伙伴们留言)。学习一种技术,我们一般都希望尽量获取“第一手”资料。在本博客,博主会分享自己如何从 Spring Boot 官网中获取想要的信息,搭建自己的 Spring Boot 项目。Spring Boot 的项目有很多种...

Java对象垃圾回收调用,JVM垃圾回收之哪些对象可以被回收_weixin_39531594的博客-程序员秘密

1.背景Java语言相比于C和C++,一个最大的特点就是不需要程序员自己手动去申请和释放内存,这一切交由JVM来完成。在Java中,运行时的数据区域分为程序计数器、Java虚拟机栈、本地方法栈、方法区和堆。其中,程序计数器、虚拟机栈和本地方法栈是线程私有的,线程销毁后自动释放。垃圾回收的行为发生在堆和方法区,主要是堆,而堆中存储的主要是对象。那么自然而然地就会有这么几个问题,哪些对象可以被回收?通...