慕运维2862311
2016-11-04 22:20
package cn.itcast.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class Dbunit { private static final String URl ="jdbc:mysql://localhost:3306/admin"; private static final String USRE="admin"; private static final String PASSWORD="admin"; public static void main(String[] args) throws Exception { Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection(URl, USRE, PASSWORD); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select * from students"); while(rs.next()){ System.out.println(rs.getInt("ID") + rs.getString("name")); } } } Exception in thread "main" java.sql.SQLException: Access denied for user 'admin'@'localhost' (using password: NO) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871) at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1694) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1215) at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2255) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2286) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2085) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44) 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.jdbc.Util.handleNewInstance(Util.java:404) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at cn.itcast.jdbc.Dbunit.main(Dbunit.java:19)
Access denied for user 'admin'@'localhost'。数据库连接拒绝,看看本地MySQL数据库用户名为admin的密码是不是对的
JDBC之 “ 对岸的女孩看过来”
99327 学习 · 856 问题
相似问题