这是我的代码-
公共类DataBaseConnection {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con= DriverManager.getConnection("jdbc:mysql://localhost:3306/nitya", "username", "password");
Statement s=con.createStatement();
ResultSet r=s.executeQuery("select * from employee");
while(r.next()) {
System.out.println(r.getInt(1));
}
}
}
我遇到的错误-
Exception in thread "main" java.sql.SQLException: Access denied for user 'ss'@'localhost' (using password: YES)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.stc.TestCases.DataBaseConnection.main(DataBaseConnection.java:15)
答案 0 :(得分:0)
MS SQL已在本地安装并且可以正常工作。但是在默认端口localhost:3306中,它没有打开。您能否分享我应该在getconnect方法中提供的网址? @CrazyMerlin 14