简体   繁体   English

尝试创建数据库连接时出现异常

[英]Getting exception while trying to create a database connection

I am working on a MySQL workbench and in an maven based java application I am trying to connect local database to my code.When I am doing so I am getting the following error.我正在使用 MySQL 工作台和基于 maven 的 java 应用程序,我正在尝试将本地数据库连接到我的代码。当我这样做时,我收到以下错误。 Please guide what could be the possible errors.请指导可能的错误。

Cannot create database connection
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)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:827)
    at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:447)
    at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:237)
    at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at DBconnection.createNewDBconnection(DBconnection.java:14)
    at ReadExcelFileDemo.main(ReadExcelFileDemo.java:102)
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(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)
    at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167)
    at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:340)
    at com.mysql.cj.protocol.a.NativeAuthenticationProvider.negotiateSSLConnection(NativeAuthenticationProvider.java:777)
    at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:486)
    at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:202)
    at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1348)
    at com.mysql.cj.NativeSession.connect(NativeSession.java:163)
    at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:947)
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:817)
    ... 7 more
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)
    at sun.security.ssl.ClientHandshakeContext.<init>(ClientHandshakeContext.java:98)
    at sun.security.ssl.TransportContext.kickstart(TransportContext.java:220)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:428)
    at com.mysql.cj.protocol.ExportControlled.performTlsHandshake(ExportControlled.java:316)
    at com.mysql.cj.protocol.StandardSocketFactory.performTlsHandshake(StandardSocketFactory.java:188)
    at com.mysql.cj.protocol.a.NativeSocketConnection.performTlsHandshake(NativeSocketConnection.java:99)
    at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:331)
    ... 14 more
Exception in thread "main" java.lang.NullPointerException
    at ReadExcelFileDemo.main(ReadExcelFileDemo.java:104)

Process finished with exit code 1

Your DB is not reachable because of problem on server or wrong connection settings.由于服务器问题或连接设置错误,您的数据库无法访问。 Please refer to this answer请参考这个答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试使用Java在Arango数据库中创建连接时出现“未经授权”异常 - Getting “Unauthorized” exception when trying to create connection in Arango database using Java 尝试创建文件时出现FileNotFound异常 - I'm getting FileNotFound exception while trying to create a file 尝试创建SQL Lite数据库时获取NullPointerException-Android - Getting an NullPointerException while trying to create a SQL Lite database - Android 尝试使用Hibernate创建MySQL连接时发生异常 - Exception when trying to create MySQL connection with Hibernate 尝试获取FileOutputStream时获取异常 - Getting exception while trying to get FileOutputStream 登录中的异常::无法创建与数据库服务器的连接 - Exception in Login:: Could not create connection to database server 异常无法创建与数据库服务器的连接 - exception could not create connection to database server 如何在 Spring 引导中使用 JPA 从数据库中获取特定列(尝试从数据库中获取特定列时出现异常)? - How to get specific columns from database using JPA in Spring Boot (Getting Exception while trying to fetch specific column from Database)? 尝试从Access数据库获取连接时挂起应用程序 - Hangs on application while trying to get connection from access database 尝试通过https调用服务时出现异常 - Getting Exception while trying to call a service over https
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM