简体   繁体   English

Java jooq插入查询不起作用

[英]Java jooq insert query isn't working

Here's the code that I'm using to insert into the table. 这是我要插入到表中的代码。

    try (Connection conn = DriverManager.getConnection(URL, USER, PASS)) {
            DSLContext create = DSL.using(conn, SQLDialect.MYSQL);
            uuid = UUID.randomUUID();
            create.insertInto(ACCOUNTS, ACCOUNTS.ID, ACCOUNTS.ONESIGNAL_ID, ACCOUNTS.EMAIL, ACCOUNTS.AGE, ACCOUNTS.UUID_L, ACCOUNTS.UUID_M)
                        .values(userId, oneSignalId, email, (int)age, uuid.getLeastSignificantBits(), uuid.getMostSignificantBits());
    } catch (SQLException e) { 
        e.printStackTrace(); 
    }

It's not inserting the row, and it's also not throwing any kind of errors, so I'm at a loss as to what's wrong, perhaps someone with experience can help me out. 它没有插入行,也没有引发任何类型的错误,所以我对问题出了什么迷茫,也许有经验的人可以帮助我。

Also, is it possible to check rather or not the insert statement completed successfully or not? 另外,是否可以检查插入语句是否成功完成? JooQ seems a little more complicated than JDBC, but everyone tells me to use JooQ instead. JooQ似乎比JDBC复杂一些,但是每个人都告诉我使用JooQ。

Thanks. 谢谢。

You didn't call .execute() : 您没有调用.execute()

try (Connection conn = DriverManager.getConnection(URL, USER, PASS)) {
        DSLContext create = DSL.using(conn, SQLDialect.MYSQL);
        uuid = UUID.randomUUID();
        create.insertInto(ACCOUNTS, ACCOUNTS.ID, ACCOUNTS.ONESIGNAL_ID, ACCOUNTS.EMAIL, ACCOUNTS.AGE, ACCOUNTS.UUID_L, ACCOUNTS.UUID_M)
              .values(userId, oneSignalId, email, (int)age, uuid.getLeastSignificantBits(), uuid.getMostSignificantBits())
              .execute();
} catch (SQLException e) { 
    e.printStackTrace(); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM