处理无法连接到Mysql

时间:2012-11-15 06:26:45

标签: java mysql processing

我一直在努力将处理草图连接到我的wamp服务器中的mysql,但是我遇到了sql错误,说明访问被拒绝

这是我的代码:

MySQL msql;


void setup()
{
    size( 100, 100 );
    String user     = "root";
    String pass     = "xxxx";

    String database = "test";

    msql = new MySQL( this, "localhost", database, user, pass );

    if ( msql.connect() )
    {
        msql.query( "SELECT COUNT(*) FROM temp" );
        msql.next();
        println( "number of rows: " + msql.getInt(1) );
    }
    else
    {
        // connection failed !
    }
}

void draw()
{
    //  visual sketch ...
}

我的用户名和密码与我的phpmyadmin以及mysql控制台一起工作正常。但在处理中我得到这个错误。

SQL.connect(): Could not connect to the database ( jdbc:mysql://localhost/test ).

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
    at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4612)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1296)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2412)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2445)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2230)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:813)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:334)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at SQL.connect(SQL.java:132)
    at MySQL_example1.setup(MySQL_example1.java:65)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:662)

0 个答案:

没有答案