Home > Back-end >  Mysql JDBC link: error: can't find or unable to load the main class d
Mysql JDBC link: error: can't find or unable to load the main class d

Time:10-28

Have imported driver class, the database is open, the code also didn't see what is wrong is displayed - error: cannot find or unable to load the main class d

UserDemo2. Java:
Import the Java. SQL. Connection;
Import the Java. SQL. DriverManager;
Import of Java, SQL PreparedStatement;
Import the Java. SQL. The ResultSet;
Import the Java. SQL. SQLException;



Public class UserDemo2 {
//define database driver link path
Private static final String url="JDBC: mysql://localhost: 3306/test".
Private static final String username="root";
Private static final String password="sjH13351292490";
The Connection conn=null;
//links database method
Public void getConnection () {//static
Try {
//1. The load driver
Class.forName("com.mysql.jdbc.Driver");
//2. Create a database link object
Conn=DriverManager.
GetConnection (url, username, password);
System. The out. Println (" database link success ");
} the catch (a ClassNotFoundException e) {
e.printStackTrace();
System. The out. Println (" database load failure ");
} the catch (SQLException e) {
e.printStackTrace();
System. The out. Println (" database link failure "+ e. oString ());
}
}
//user name and password is correct
Public void findNamePassored (String name, String password) {
//define the SQL statement
String SQL="select * from the where name=? And password=?" ;
Try {
//create a statement object
//executing SQL statements
PreparedStatement ps=conn. PrepareStatement (SQL);//the precompiled
ps.setString(1, name);
Ps. SetString (2, password);
The ResultSet rs=ps. ExecuteQuery ();
{if (rs. Next ())
System. The out. Println (" the user ");
} else {
System. The out. Println (" the user does not exist ");
}
} the catch (SQLException e) {
e.printStackTrace();
}


}
}

D.j ava:
Public class d {
Public static void main (String [] args) {
UserDemo2 user=new UserDemo2 ();
The user. The getConnection ();
User. FindNamePassored (" zmz1 ", "123");
}
}

CodePudding user response:

You are here to make a breakpoint, look for to the object it
Conn=DriverManager.
GetConnection (url, username, password);
  • Related