当我向 DriverManager.getConnection 指定用户名和密码时,它返回一个错误,指出我没有使用密码
我正在尝试建立与 MySQL 数据库的连接,但是当我尝试连接时出现错误:
SQLException: 用户 'test'@'localhost' 的访问被拒绝(使用密码:NO) SQL状态:28000 VendorError: 1045
这是我尝试获取连接的 Java 程序,并且我正在向 DriverManager.getConnection 提供密码。
//import java.sql.Connection;
//import java.sql.DriverManager;
//import java.sql.SQLException;
import java.sql.*;
//import com.mysql.jdbc.Driver;
public class jconnector_test{
public static void main (String[] args) {
try{
Class.forName("com.mysql.jdbc.Driver");
//DriverManager.registerDriver (new Driver());
}
catch(Exception x)
{
System.out.println("Unable to load the driver class!" + x);
}
Connection conn = null;
String url = "jdbc:mysql://localhost/test";
String user = "test";
String password = "test";
try {
conn = DriverManager.getConnection(url, user, password);
//do something with the Connection
}
catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
}
}
SQLException:用户“test”@“localhost”的访问被拒绝(使用密码:NO) SQL状态:28000 供应商错误:1045
I am trying to establish a connection to MySQL database but when I attempt to connect I get the error:
SQLException: Access denied for user 'test'@'localhost' (using password: NO)
SQLState: 28000
VendorError: 1045
This is the Java program I am attempting to get the connection with and I am providing a password to the DriverManager.getConnection.
//import java.sql.Connection;
//import java.sql.DriverManager;
//import java.sql.SQLException;
import java.sql.*;
//import com.mysql.jdbc.Driver;
public class jconnector_test{
public static void main (String[] args) {
try{
Class.forName("com.mysql.jdbc.Driver");
//DriverManager.registerDriver (new Driver());
}
catch(Exception x)
{
System.out.println("Unable to load the driver class!" + x);
}
Connection conn = null;
String url = "jdbc:mysql://localhost/test";
String user = "test";
String password = "test";
try {
conn = DriverManager.getConnection(url, user, password);
//do something with the Connection
}
catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
}
}
SQLException: Access denied for user 'test'@'localhost' (using password: NO)
SQLState: 28000
VendorError: 1045
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论