得到“查询不返回结果”。 SQL异常 [英] Getting "Query does not returns results" SQL exception

查看:206
本文介绍了得到“查询不返回结果”。 SQL异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I was trying to make a register program in Java in Eclipse. But i got an error :

java.sql.SQLException: Query does not return results

您可以看到我的以下代码:

You can see my following code :

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

of:

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

    }

}

有人可以帮忙吗请问我谢谢:)!

Can someone help me please ? Thanks :) !

推荐答案

对于 INSERT UPDATE Delete 使用 executeUpdate()方法并用于 SELECT 使用 executeQuery()方法返回 ResultSet

For INSERT, UPDATE or DELETE use the executeUpdate() method and for SELECT use the executeQuery() method which returns the ResultSet.

这篇关于得到“查询不返回结果”。 SQL异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆