2016-05-06 22 views
1

我試圖在Eclipse中製作一個註冊程序在Java中。 但我得到了一個錯誤:獲取「查詢不返回結果」SQL異常

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(); 

    } 

} 

有人能幫助我嗎?謝謝 :) !

回答

4

對於INSERT,UPDATE或DELETE,使用executeUpdate(),select用於使用返回ResultSet的executeQuery()。

+0

感謝您的迴應,我將嘗試它:)! –

+0

非常感謝安德魯TR! :D –

+0

感謝您的回答:) – mesutpiskin