Hobbyist
Hobbyist

Reputation: 16192

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.

Thanks.

Upvotes: 1

Views: 1703

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 220842

You didn't call .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(); 
}

Upvotes: 1

Related Questions