Home > database >  The Exception in the thread "main" Java. SQL. SQLException: Access denied for user 'r
The Exception in the thread "main" Java. SQL. SQLException: Access denied for user 'r

Time:09-25

Package cn. Itcast. JDBC. Example;
Import the Java. SQL. Connection;
Import the Java. SQL. DriverManager;
Import the Java. SQL. The ResultSet;
Import the Java. SQL. SQLException;
Import Java, SQL Statement;
Import the Java. SQL. The Date;
Public class Example01 {
Public static void main (String [] args) throws SQLException {
The Statement STMT=null;
The ResultSet rs=null;
Connection conn=null;
Try {
//
Class.forName("com.mysql.jdbc.Driver");

The String url="JDBC: mysql://localhost: 3306/JDBC";
String username="root";
String password="123456";
Conn=DriverManager. GetConnection (url, username, password);

STMT=conn. CreateStatement ();
//
String SQL="select * from the users";
Rs=STMT. ExecuteQuery (SQL);
//
System. The out. Println (" id | name | password | email | birthday ");
While (rs), next ()) {
Int id=rs. Get int (" id ");//
String name=rs. Get String (" name ");
String PSW=rs. Get String (" password ");
The String email=rs. Get String (" email ");
The Date birthday=rs. GetDate (" birthday ");
System. Out.println (id + "|" + name + + PSW + "|" "|" + email
+ + birthday "|");
}
} the catch (a ClassNotFoundException e) {
e.printStackTrace();
} the finally {
//
If (rs!=null) {
Try {
rs.close();
} the catch (SQLException e) {
e.printStackTrace();
}
Rs=null;
}
If (STMT!=null) {
Try {
STMT. Close ();
} the catch (SQLException e) {
e.printStackTrace();
}
STMT=null;
}
if(conn!=null) {
Try {
conn.close();
} the catch (SQLException e) {
e.printStackTrace();
}
Conn=null;
}
}
}
}
This is an error:
The Exception in the thread "main" Java. SQL. SQLException: Access denied for user 'root' @ 'localhost' (using password: YES)
At com. Mysql. JDBC. SQLError. CreateSQLException (SQLError. Java: 946)
At com. Mysql. JDBC. MysqlIO. CheckErrorPacket (MysqlIO. Java: 2985)
At com. Mysql. JDBC. MysqlIO. CheckErrorPacket (MysqlIO. Java: 885)
At com. Mysql. JDBC. MysqlIO. SecureAuth411 (MysqlIO. Java: 3421)
At com. Mysql. JDBC. MysqlIO. DoHandshake (MysqlIO. Java: 1247)
At com. Mysql. JDBC. Connection. CreateNewIO (2775) Connection. Java:
At com. Mysql. JDBC. Connection. & lt; init> (1555) Connection. Java:
At com. Mysql. JDBC. NonRegisteringDriver. Connect (NonRegisteringDriver. Java: 285)
The at Java. SQL. DriverManager. GetConnection (Unknown Source)
The at Java. SQL. DriverManager. GetConnection (Unknown Source)
The at cn. Itcast. JDBC. Example. Example01. Main (20) Example01. Java:
The Internet to find fault tried I can't find a great god

CodePudding user response:

The mysql database user root in the table corresponding to the host to try %

CodePudding user response:

Select the user and the host from mysql. The user to see a ha
  • Related