1

Im using my root account to login to mysql from a javafx app but im denied with Acces Denied ''@'localhost' (using password: NO). This is my code:

    public void ConnnectClicked(ActionEvent e) throws SQLException {
    try {
        Class.forName("com.mysql.jdbc.Driver");
    } catch (ClassNotFoundException ex) {
        System.out.println("Error: unable to load driver class!");
        System.exit(1);
    }
    String URL = "jdbc:mysql://localhost:3306/world";
    String name = username.getSelectedText();
    String pass = password.getSelectedText();

    Connection conn = DriverManager.getConnection(URL, name, pass);
    primaryStage.setScene(country);
}

As you can see its just a basic connection scheme in javafx. Doenst "password no" means theres something worng with my user account?

  • 1
    if you print out name and pass on the console, is it what you expect to see? – peterulb Jun 05 '17 at 12:18
  • 1
    See https://stackoverflow.com/questions/2995054/access-denied-for-user-rootlocalhost-using-passwordno – Demogorii Jun 05 '17 at 12:18
  • I cant get anything to print. – Neil A Jones Jun 05 '17 at 12:26
  • I get no error when manually putting in the pass and name. Im guessing its a problem with my textfields not passing their strings. Thanks for the help anyway. Ill continue to work on my textfields to see what going on. – Neil A Jones Jun 05 '17 at 12:35
  • 1
    The error indicates that `name` and `pass` were empty. Maybe you don't want `getSelectedText`, but `getText` (or something similar) instead. – Mark Rotteveel Jun 05 '17 at 12:46
  • Figured it out. I needed to use getText() instead of getSelectedText(). Im a bit rusty so thanks for putting up with me. – Neil A Jones Jun 05 '17 at 12:50

1 Answers1

3

It's just a guess, but if those are text boxes:

String name = username.getSelectedText();
String pass = password.getSelectedText();

Then you should propably use username.getText(), because selectedText is the text you marked with your mouse. If you didnt mark it (blue highlighting), then it's empty.

Dennux
  • 240
  • 1
  • 8