Java内存HSQLDB

问题描述

我正在使用Java不和谐机器人,我用HsqlDB的内存数据库,但它不工作对我很好,我将数据插入表和结果集下一次给出了0行。最令人困惑的一点是,它在之前的另一特征在机器人工作

代码

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,'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,但我这样做,一个sql服务器支持这样做了调试,他们都没有工作。

查询创建表

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

解决方法

user 是保留的 SQL 关键字。您不应将其用作列名。

我使用您的架构重现了该问题 - 将列重命名为“userid”使一切都按预期工作。

user 被本页确认为保留关键字:https://www.drupal.org/docs/develop/coding-standards/list-of-sql-reserved-words