3
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操作系统中使用eclipse配置mysql。但是当我试图运行该程序时,我得到如下的错误。用eclipse创建数据库的问题
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)
我发现在论坛上同样的问题,但并没有解决我的问题......可能这是由于操作系统的改变,如果不是请原谅我的无知和请通过this..thanks指导您的帮助...安装mySQL时设置的root密码是“welcome”..
例外情况是清楚的:即用户名和密码不具有对数据库的访问。与DBA交谈。您必须授予对该主机连接到数据库的用户名和密码的访问权限。 – duffymo
如何与DBA交谈...什么是DBA ...请原谅abt数据库什么都不知道......试图学习.. :) – Sud
数据库管理员 - 拥有数据库的人。如果那是你,你需要了解如何去做。您通常在Java之外创建数据库和表。您可以与存在的电路图进行交互。 – duffymo