This discussion is archived
10 Replies Latest reply: May 3, 2013 4:38 AM by gimbal2 RSS

Having connection issues with Java 8 and mysql

KonradZuse Explorer
Currently Being Moderated
 public void sql() throws SQLException
      {
        try 
        {
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql", "root", "*******");
             // Statement state = con.createStatement();
            System.out.println("kaw");
        } 
        catch (ClassNotFoundException ex)
        {
            Logger.getLogger(draw.class.getName()).log(Level.SEVERE, null, ex);
        }
I would appreciate any help, thanks,

~KZ



So now I can connect to the db, but when my program is finished loading I get
SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
So now it seems I'm back to where my error began...... >(?

Edited by: KonradZuse on Apr 25, 2013 1:59 PM

Edited by: KonradZuse on Apr 26, 2013 1:06 AM
  • 1. Re: Having connection issues with Java 8 and mysql
    rp0428 Guru
    Currently Being Moderated
    >
    Class Not Found Exception: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    >
    That exception means that the JDBC jar file for mysql is not on the classpath.

    Add your jar file to the classpath.
  • 2. Re: Having connection issues with Java 8 and mysql
    gimbal2 Guru
    Currently Being Moderated
    And probably remove that Class.forName() line entirely as it is not needed anymore.
  • 3. Re: Having connection issues with Java 8 and mysql
    KonradZuse Explorer
    Currently Being Moderated
    I fixed all of that, now I just need to know why I'm getting this Password('no') error...?
  • 4. Re: Having connection issues with Java 8 and mysql
    gimbal2 Guru
    Currently Being Moderated
    Since you destroyed half your original post I don't know which version of Connector/J you're using. Try the latest one (5.1.24), perhaps your version is older and there is some sort of stupid incompatibility in it. Or perhaps you're just prematurely using Java 8.

    in the future please leave your original post alone and post updates in new replies.
  • 5. Re: Having connection issues with Java 8 and mysql
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    gimbal2 wrote:
    And probably remove that Class.forName() line entirely as it is not needed anymore.
    However leaving it in is the only sure way that one can in fact determine that the jar is missing versus an incorrect connection string.
  • 6. Re: Having connection issues with Java 8 and mysql
    KonradZuse Explorer
    Currently Being Moderated
    Sorry I deleted it to make it clearer I guess that didn't work...


    I am using 5.1.24

    I made sure the DB look to that when I created the connection usign Connector/J

    I edited my code to what that example has shown.

    public void sql() throws SQLException
    {


    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql", "root", "Konrad^^Zuse$$");
    if (con != null)
    {
    System.out.println("Connected to the database test1");
    }

    }

    When I run it, it says it connects, then a few seconds later when the gui portion of my program starts up, which is JavaFX based(since I put sql() at the top of my start(Stage stage) method; however why doesn't the SQL error happen right away)? It should be thrown based on the sql method itself, not anything else...?

    The error is
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    SQL Exception: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    Again I am using a password, I have created multiple connections using the password(it wont let me create it otherwise). The connection is established(if I change the password or have none it throws an error)... So I'm confused... Maybe like you said it's because I'm using Java 8 I will report back on 1.7
  • 7. Re: Having connection issues with Java 8 and mysql
    Tolls Journeyer
    Currently Being Moderated
    And if 1.7 has the same problems, you might consider looking for a stack trace, if nothing else it could point to where this is occurring.
  • 8. Re: Having connection issues with Java 8 and mysql
    gimbal2 Guru
    Currently Being Moderated
    jschell wrote:
    gimbal2 wrote:
    And probably remove that Class.forName() line entirely as it is not needed anymore.
    However leaving it in is the only sure way that one can in fact determine that the jar is missing versus an incorrect connection string.
    That is a good point.

    I just cannot believe that the posted code is actually the code that is causing the problem. As the logs state its not only about no password being passed, its also about no user being passed (empty@localhost). It all just looks like there is a hidden piece of (test?) code being executed here.

    I would also expand the connection test code to actually execute a select statement. If that works then there must be other code in play somewhere.
  • 9. Re: Having connection issues with Java 8 and mysql
    KonradZuse Explorer
    Currently Being Moderated
    Sorry to come back into this so late, but I have been doing other things. Basically I tried it on 7.3, it worked, then I tried making my own class in 8 and it also worked... I realized I had a second connection running into my listCell subclass which kept causing the multiple errors we've seen. I didn't even realize this existed, so boo :(. Thanks for the help, glad it was a "stupid" error.
  • 10. Re: Having connection issues with Java 8 and mysql
    gimbal2 Guru
    Currently Being Moderated
    KonradZuse wrote:
    Thanks for the help, glad it was a "stupid" error.
    It usually is although I call them silly errors, stupid is so negative. You just need to keep assuming its something simple and keep looking :)

    EDIT:

    oddly enough I managed to trigger the same misleading connection error on Java 6 using a current driver just half an hour ago. I got it because I passed to wrong user, not 'no user'. I guess the exception message is filtered to not show something as potentially hazardous to security as a database username.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points