获取"查询不会返回结果" SQL异常

时间:2016-05-06 23:43:58

标签: java eclipse

我试图在Eclipse中用Java创建一个注册程序。 但是我收到了一个错误:

java.sql.SQLException: Query does not return results

您可以看到以下代码:

Login.addnewuser(lblname.getText(), lblusername.getText(), lblpseudo.getText(), passwordField.getText(), rankchoice.getSelectedItem());

    public static void addnewuser(String Name, String Username, String Pseudo, String Password, String Rank) {

    String query = ("INSERT INTO UsersInfos (Name, Username, Pseudo, Password, Rank) " + "VALUES ('"  + Name +  "' , '"  + Username +  "' , '"  + Pseudo +  "' , '"  + Password +  "' , '"  + Rank +  "')");

    connection = SqliteConnection.dbConnector();

    try {

        PreparedStatement name2 = connection.prepareStatement(query);
        name2.executeQuery();

    } catch (SQLException e) {

        e.printStackTrace();

    }

}

有人可以帮助我吗?谢谢:)!

1 个答案:

答案 0 :(得分:10)

对于INSERTUPDATEDELETE使用executeUpdate()方法,SELECT使用executeQuery()方法返回{{1} }}