import Java. SQL. *;
Public class Demo01_1 {
Public static void main (String [] args) {
Try {
Class.forname (". Com. Mysql. Cj. JDBC Driver ");//load the mysql driver
The String url="JDBC: mysql://localhost: 3306/sys".//database configuration information
String username="root";//database login account
String password="XXXX";//database password
The Connection con=DriverManager. GetConnection (url, username, password);
System. The out. Println (con);
Con. The close ();//close the database
} the catch (a ClassNotFoundException e) {
e.printStackTrace();
} the catch (SQLException e) {
e.printStackTrace();
}
}
}
But when I write the rest of the program (also import the jar package), trying to connect to the database, an error: the Exception in the thread "is the main" Java. SQL. SQLException: Access denied for user '@' localhost '(using password: NO)
May I ask what is the problem?
CodePudding user response:
What other programs, it see,CodePudding user response:
Two program is written on the same machine (environment)? Two pieces of code written to connect to the database? Can directly use the mysql command on your database?CodePudding user response:
Suggest NO input password, using the password: NO, that didn't put the password in the connection, you see the driver is correctCodePudding user response: