Results 1 to 4 of 4
  1. #1
    mitty is offline Member
    Join Date
    Jan 2010
    Posts
    16
    Rep Power
    0

    Default Connecting a MySQL DB through Eclipse

    Hi Guys. I'm a complete beginner using Java.

    I've created a database called NLP_test with a table called customer

    im using Eclipse to try connecting to the DB with the following code

    (p.s i've looked around the net and compiled this from bits and bobs to try but had no joy.)

    import java.sql.*;
    import javax.sql.*;

    public class JDBCDemo


    String Url = "jdbc:mysql://localhost:3306/NLP_test";
    String Class = "com.mysql.jdbc.Driver";
    String username = "root"
    String password = "k6cbzq4qw2"


    try {

    Class.forName("com.mysql.jdbc.Driver");
    connectionObject = DriverManager.getConnection ("com.mysql.jdbc.Driver","root","k6cbzq4qw2");
    StatementObject = con.createStatement();
    }

    catch (Exception e)
    {
    System.err.println("problems connecting to " + Url);
    }


    im getting the following error...

    java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:1072)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:3563)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:3495)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:919)
    at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java: 4001)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:12 84)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(Connecti onImpl.java:2183)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImp l.java:784)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connect ion.java:46)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:40 6)
    at com.mysql.jdbc.ConnectionImpl.getInstance(Connecti onImpl.java:354)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:284)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at jdbcdemo.main(jdbcdemo.java:16)

    thanks in advance guys

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,535
    Blog Entries
    7
    Rep Power
    20

    Default

    Try the String "127.0.0.1" instead of "localhost".

    kind regards,

    Jos

  3. #3
    mitty is offline Member
    Join Date
    Jan 2010
    Posts
    16
    Rep Power
    0

    Default

    I tried changing localhost but it didnt work. the same error is showing still.

    anyone else have any ideas?

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default

    You've defined a bunch of strings at the top for your url, classname and login stuff, yet you don't use them. More importantly, look at the url you have passed into getConnection().

Similar Threads

  1. Connector J with Eclipse and MySQL 5.0.x
    By int80 in forum Eclipse
    Replies: 11
    Last Post: 05-31-2010, 09:32 AM
  2. Eclipse / Mysql problem
    By jdevm in forum Eclipse
    Replies: 0
    Last Post: 10-09-2008, 01:16 AM
  3. hello the community & mysql connecting problems
    By scchia in forum New To Java
    Replies: 6
    Last Post: 07-16-2008, 08:49 AM
  4. problem in connecting to mysql database
    By nancyv in forum Java Servlet
    Replies: 6
    Last Post: 04-02-2008, 11:33 AM
  5. connecting to mysql database
    By javagal in forum NetBeans
    Replies: 2
    Last Post: 08-04-2007, 12:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •