在JavaFX中使用MySQL的用户''@ localhost'(使用密码:NO)拒绝访问

时间:2022-01-01 19:18:18

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:

我使用我的root帐户从javafx应用程序登录到mysql但我拒绝使用Acces Denied''@ localhost'(使用密码:NO)。这是我的代码:

    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?

正如你在javafx中看到它只是一个基本的连接方案。 Doenst“密码否”意味着我的用户帐户有什么问题?

1 个解决方案

#1


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.

然后你应该使用username.getText(),因为selectedText是你用鼠标标记的文本。如果你没有标记它(蓝色突出显示),那么它是空的。

#1


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.

然后你应该使用username.getText(),因为selectedText是你用鼠标标记的文本。如果你没有标记它(蓝色突出显示),那么它是空的。