【问题标题】:Getting "Query does not returns results" SQL exception获取“查询不返回结果”SQL异常
【发布时间】:2016-05-06 23:43:57
【问题描述】:

我试图在 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();

    }

}

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

【问题讨论】:

标签: java eclipse


【解决方案1】:

对于INSERTUPDATEDELETE,使用executeUpdate() 方法,对于SELECT,使用executeQuery() 方法,该方法返回ResultSet

【讨论】:

  • 感谢您的回复,我去试试看:)!
猜你喜欢
  • 2012-05-08
  • 2020-03-31
  • 1970-01-01
  • 2011-04-17
  • 1970-01-01
  • 2020-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多