import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;public class MysqlJdbc { public static void main(String args[]) { try { Class.forName("com.mysql.cj.jdbc.Driver"); //加载MYSQL JDBC驱动程序 System.out.println("成功"); } catch (Exception e) { System.out.print("失败"); e.printStackTrace(); } try { Connection connect = DriverManager.getConnection( "jdbc:mysql://localhost:3306/123"," root","123"); //连接URL为 jdbc:mysql//服务器地址/数据库名 ,后面的2个参数分别是登陆用户名和密码 System.out.println("成功连接数据库"); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from user"); //user 为你表的名称while (rs.next()) { System.out.println(rs.getString("name")); } } catch (Exception e) { System.out.print("错误开始 : "); e.printStackTrace(); } }}错误提示:成功错误开始 : java.sql.SQLNonTransientConnectionException: CLIENT_PLUGIN_AUTH is required at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:550) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:537) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:527) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:512) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:480) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:498) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:494) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:72) at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1634) at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:637) at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:351) at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:224) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at com.meiju.com.MysqlJdbc.main(MysqlJdbc.java:19)Caused by: com.mysql.cj.core.exceptions.UnableToConnectException: CLIENT_PLUGIN_AUTH is required 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.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:54) at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:73) at com.mysql.cj.mysqla.io.MysqlaProtocol.rejectConnection(MysqlaProtocol.java:319) at com.mysql.cj.mysqla.authentication.MysqlaAuthenticationProvider.connect(MysqlaAuthenticationProvider.java:207) at com.mysql.cj.mysqla.io.MysqlaProtocol.connect(MysqlaProtocol.java:1361) at com.mysql.cj.mysqla.MysqlaSession.connect(MysqlaSession.java:132) at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:1754) at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1624) ... 6 more
添加回答
举报
0/150
提交
取消