【发布时间】:2014-10-06 07:29:36
【问题描述】:
我需要使用动态构造的 SQL 进行批量插入。
我发现文档中的示例都使用 jOOQ 生成的表包装类,我在这里没有,我不希望必须弄清楚和指定列名(插入使用表中的所有列定义的顺序)。
我该怎么做?
我尝试了以下方法,但它不起作用(绑定变量最终都为 NULL)。
import org.h2.Driver;
import org.jooq.DSLContext;
import org.jooq.impl.DSL;
import org.junit.Test;
public class BatchBindTest {
@Test
public void test() throws SQLException {
Connection conn = new Driver().connect("jdbc:h2:./batchBindTest", null);
DSLContext x = DSL.using(conn);
x.execute("create table test(id integer not null)");
// this does not work, value is not bound
x.batch("insert into test values(?)").bind(1).execute();
}
}
【问题讨论】: