
今天遇见一个这个问题,解决后发出来分享一下:
我下载了mysql-connector-java-8.0.11.jar
报错“Connected to the target VM, address: '127.0.0.1:59549', transport: 'socket' Wed Sep 13 16:56:02 CST 2023 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. java.sql.SQLException: Access denied for user 'username'@'localhost' (using password: YES) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:127) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) 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(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at BookManagement.<init>(BookManagement.java:21) at BookManagement.main(BookManagement.java:62) Disconnected from the target VM, address: '127.0.0.1:59549', transport: 'socket' 进程已结束,退出代码 0
这个错误表明有两个问题:
useSSL=false 参数来禁用 SSL。
将此行:
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/BookManagement", "username", "password");改为:
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/BookManagement?useSSL=false", "username", "password");处理访问拒绝问题:
localhost 访问。"username" 和 "password"。例如,如果你的 MySQL 用户名是 root,密码是 mysecret,那么连接代码应更改为:应用上述更改后,再次运行你的程序。这应该会解决你遇到的问题。