4
votes

I am insert a record to MySql using JOOQ , this is my code

if (f.getConnection()!=null) {
    UserRecord us = new UserRecord();
    us.setAccountId(UInteger.valueOf(accountId));
    us.setCode(code);
    us.setEnd(new java.sql.Date(end.getTime()));
    us.setStart(new java.sql.Date(start.getTime()));
    us.setPhoneNumberId(UInteger.valueOf(phnNUmberId));            
    us.store();
}

(f is database connection factory class)
It gives
Exception in thread "main" org.jooq.exception.DetachedException: Cannot execute query. No Connection configured

But database connection is nut null , What can be the reason ?
(select queries are working with same connection)

1

1 Answers

10
votes

Your user record is not "attached" to that Factory (jOOQ 2.0, in more recent versions, it's called Configuration). You have two options:

// Attach the user record prior to calling "store"
f.attach(us);
us.store();

// Create a pre-attached user record:
UserRecord us = f.newRecord(Tables.USER);
// [...]
us.store();

If unattached, there's no way for jOOQ to discover what Factory (Configuration) should be used to store your record.