Home > Back-end >  The JDBC connection problem again
The JDBC connection problem again

Time:09-22

When writing the first about the JDBC application, application can run normally
 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 correct

CodePudding user response:

refer to the second floor qybao 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?


Writing is the same, even copy the same file can run,
Using CMD can be directly run mysql,

I guess it is possible that install mysql problems? When installed mysql and download the MAMP at that time, then every time before using CMD running mysql open MAMP,
More strange is using CMD running mysql password and JDBC run password is not the same... With JDBC run password is registered in mysql I set password, is the default password with CMD running mysql password root...

CodePudding user response:

Check the password for the wrong, the client can connect under the screen

CodePudding user response:

I am also the same problem as well, can't find the solution

CodePudding user response:

Solved, how to solve
  • Related