JOOQ未配置连接问题

use*_*690 3 java mysql jooq

我正在使用JOOQ向MySql插入一条记录,这是我的代码

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();
}
Run Code Online (Sandbox Code Playgroud)

(f是数据库连接工厂类)

在线程“ main” org.jooq.exception.DetachedException中给出异常:无法执行查询。未配置连接

但是数据库连接没有螺母,这可能是什么原因?
(某些查询使用相同的连接)

Luk*_*der 10

您的用户记录未“附加”到该记录Factory(jOOQ 2.0,在较新的版本中称为Configuration)。您有两种选择:

// 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();
Run Code Online (Sandbox Code Playgroud)

如果未附加,jOOQ将无法发现应使用哪个工厂(配置)来存储您的记录。