【问题标题】:can't able to connect mysql server connection无法连接mysql服务器连接
【发布时间】:2019-11-16 20:28:08
【问题描述】:

这是我的代码 -

公共类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)

【问题讨论】:

  • 答案在异常中:权限被拒绝。检查用户表中的用户主机是否真的是“localhost”。检查该用户对该数据库(可能还有表)的授予权限。
  • 你的代码与硒无关

标签: java mysql jdbc


【解决方案1】:

MS SQL 已在本地安装并且工作正常。但是在默认端口 localhost:3306 中它没有打开。你能分享一下我应该在getconnect方法中提供哪个网址吗? @CrazyMerlin 14

【讨论】:

    猜你喜欢
    • 2015-05-10
    • 2012-11-03
    • 2019-05-13
    • 2020-09-13
    • 2012-11-12
    • 2014-03-04
    • 2014-07-15
    相关资源
    最近更新 更多