Grouping heterogeneous prepared SQL queries with Groovy?

Batch insert using groovy Sql? discusses how to execute several prepared statements in a package. But all statements must have the same structure (passed as a top-level argument to withBatch).

Is there a way to run heterogeneous prepared statements, such as:

sql.withBatch {ps ->
    ps.addBatch("insert into t1 values(:a, :b)", [a:1, b:2])
    ps.addBatch("insert into t2 values(:c)", [c:3])
}

(This throws an exception because it addBatchdoes not have such a signature.)

+4
source share
2 answers

As described in Oracle Documentation :

: .

: , , UPDATE, DELETE INSERT , . .

IBM :

JDBC, JDBC 2.0 . DB2 (R) , JDBC . , .

, , . . , , . . , .

, . , , - :

SQL :

:

  • ( )

, .

:

sql.withBatch(20, "insert into t1 values(:a, :b)") {
    ...
}
sql.withBatch(20, "insert into t2 values(:c)") {
    ...
}

,

sql.withBatch {ps ->
    ps.addBatch("insert into t1 values(1, 2)")
    ps.addBatch("insert into t2 values(3)")
}

, : , JDBC .

+1

(docs), . , .

+1

All Articles