我正在尝试将JDBC项目从Eclipse连接到MySQL。我不断收到相同的错误消息:
com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException:客户端 不支持服务器请求的身份验证协议;考虑 升级MySQL客户端
在以下代码行上:
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/WorldFootball","root","");
WorldFootball是我在MySQL中创建的数据库
我正在使用最新版本的MySQL版本8.0.16
下面是我的完整Java代码
import java.sql.*;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.Connection;
public class SQL {
public static void main(String[] args) throws InstantiationException,
IllegalAccessException, ClassNotFoundException {
// TODO Auto-generated method stub
try {
String Driver = "com.mysql.jdbc.Driver";
Class.forName(Driver);
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/WorldFootball","root","");
Statement stmt=con.createStatement();
String sql ="SELECT * FROM PremierLeague";
ResultSet rs=stmt.executeQuery(sql);
if (rs.next()){
System.out.println("Too Sweet");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}