eclipse的数据库创建问题

时间:2016-04-08 15:45:58

标签: java mysql ubuntu

package practice;

import java.sql.*;
import java.util.Properties;

public class DBTEst
{

  private static final String dbClassName = "com.mysql.jdbc.Driver";

  private static final String CONNECTION =
                          "jdbc:mysql://127.0.0.1/emotherearth";

  public static void main(String[] args) throws
                             ClassNotFoundException,SQLException
  {
    System.out.println(dbClassName);
    Class.forName(dbClassName);

      Properties p = new Properties();
    p.put("user","paulr");
    p.put("password","welcome");

    Connection c = DriverManager.getConnection(CONNECTION,p);

    System.out.println("It works !");
    c.close();
    }
}

我是数据库的新手,所以对于sql ..我只是在ubuntu OS中使用eclipse配置了mysql。但是当我试图运行程序时,我收到的错误如下。

com.mysql.jdbc.Driver
Exception in thread "main" java.sql.SQLException: Access denied for user 'paulr'@'localhost' (using password: YES)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1086)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:928)
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1750)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1290)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2493)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2526)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2311)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:347)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:208)
    at practice.DBTEst.main(DBTEst.java:32)

我在论坛中发现了同样的问题,但没有解决我的问题...可能是因为操作系统的改变,如果不是请求原谅我的无知,请引导通过这个...谢谢你的帮助... root我安装mySQL时设置的密码是“欢迎”..

1 个答案:

答案 0 :(得分:0)

您在设置时没有在MySQL中正确设置用户paulr,或者您可能会忽略MySQL根据客户端的IP地址或主机名进行帐户访问这一事实的常见错误。很多人忘记在用户设置中加入localhost和/或127.0.0.1

请参阅https://stackoverflow.com/a/26234768/639520