Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JOOQ No Connection configured Issue

Tags:

java

mysql

jooq

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)

like image 714
user1573690 Avatar asked Dec 26 '22 17:12

user1573690


1 Answers

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.

like image 194
Lukas Eder Avatar answered Jan 09 '23 11:01

Lukas Eder