昨天遇到一个问题:
在本地使用同样的数据库用户名与密码,可以连接数据库
使用测试连接代码,报java.sql.SQLException: Access denied for user ‘root’@'localhost
public static void main(String args[])
{
String url = "jdbc:mysql://localhost/mysql";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
}catch(Exception e){
System.out.println("无法加载驱动");
}
try {
Connection con = DriverManager.getConnection(url,"root","xxx");
if(!con.isClosed())
System.out.println("success");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
驱动是好的,问题出在密码不正确,但我明明是和cmd上写的一样。
呃,,,问题原来是出现在,进程开了2个mysql,杀死后,重新链接就行了。