I've been messing around with JDBC and trying to connect to a test database that I've created, however I keep getting this error:
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
I'm not sure how to fix this, I've tried two variations of my code both throwing back the same error here they are:
public static void main(String[] args){
Connection connection = null;
Statement statement = null;
try{
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost/feedback? user=root&password=1234");
System.out.print("Connected");
connection.close();
System.out.println("Closed");
}catch(Exception e){
System.out.println("Error: " + e);
}
}
As well as:
public class JDBC {
public static void main(String[] args) throws SQLException {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/test";
String user = "root";
String password = "1234";
System.setProperty(driver, "");
try {
DriverManager.getConnection(url,user,password);
} catch (SQLException e) {
System.out.println("Error: " + e);
}
}
}
Can anyone give me a pointer on where to go on from here?
Message is pretty much descriptive, it seems either userID, password (or) combination of both are not matching
EDIT:
After screenshot issue is related to wrong port definition in program.
Try this -
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.