Wenn ich Folgendes ausführe:
Code: Select all
SELECT USER();Aber mein Benutzername, wenn ich mich anmelde, ist ade. Wenn ich also eine Verbindung mit DriverManager herstellen möchte. getConnnection(), ich probiere beide Benutzernamen aus, aber es wird Folgendes angezeigt:
Code: Select all
Exception in thread "main" java.lang.RuntimeException: java.sql.SQLException: Access denied for user 'ade'@'localhost' (using password: YES)
at jdbcpractices.Test.main(Test.java:18)
Code: Select all
Exception in thread "main" java.lang.RuntimeException: java.sql.SQLException: Access denied for user 'root@localhost'@'localhost' (using password: YES)
at jdbcpractices.Test.main(Test.java:18)
Code: Select all
public class Test {
public static void main(String[] args) {
String user = "root"; //ade
String password = "quesadilla";
String URL = "jdbc:mysql://localhost:3306/ademysql";
try {
Connection conn = DriverManager.getConnection(URL, user, password);
System.out.println("Connected to database");
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
Mobile version