java内存hsqldb

knsnq2tg  于 2021-06-26  发布在  Java
关注(0)|答案(1)|浏览(373)

我正在使用java制作一个discord bot,我使用hsqldb作为内存数据库,但是它对我来说工作不好,我将数据插入表中,结果集下次给出0行。最令人困惑的是,它以前在bot的另一个特性中工作过
代码

String statement = "SELECT * FROM waiting_rolls WHERE user=" + sender.getIdLong() + " AND channel=" + channel.getIdLong() + "";
        System.out.println(statement);
        PreparedStatement p1 = conn.prepareStatement("SELECT * FROM waiting_rolls WHERE user='" + sender.getIdLong() + "' AND channel='" + channel.getIdLong() + "'");
        p1.execute();
        ResultSet r1 = p1.executeQuery();
        if (!r1.next()) {
            System.out.println("INSERT INTO waiting_rolls (user, channel, isWaiting) VALUES (" + sender.getIdLong() + ", " + channel.getIdLong() + ", 'true')");
            PreparedStatement p2 = conn.prepareStatement("INSERT INTO waiting_rolls (user, channel, isWaiting) VALUES (" + sender.getIdLong() + ", " + channel.getIdLong() + ", 'true')");
            p2.execute();
            EmbedBuilder embed = new EmbedBuilder();
            embed.setColor(Color.cyan);
            embed.setTitle("Create roll");
            embed.setDescription("Please insert your first value in the roll.");
            e.getChannel().sendMessage(embed.build()).queue();
        }

我知道第一个答复将被使用 p1.setLong 但是我做了这个,还有一个在sqlsupportserver中做了这个来调试,它们都不起作用
创建表的查询

CREATE TABLE waiting_rolls (channel Bigint, user Bigint, isWaiting varchar(50), lastOutput Bigint)
4nkexdtk

4nkexdtk1#

user 是保留的sql关键字。不应将其用作列名。
我使用了您的模式来重现这个问题—将列重命名为“userid”使一切都按预期工作。 user 此页确认为保留关键字:https://www.drupal.org/docs/develop/coding-standards/list-of-sql-reserved-words

相关问题