Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As described in <a href="http://docs.oracle.com/cd/E11882_01/java.112/e16548/oraperf.htm#JJDBC28752" rel="nofollow noreferrer">Oracle's documentation</a>:</p> <blockquote> <p><strong>Prepared statements</strong>: The same statement is repeated with different bind variables.</p> <p><strong>Batch updates:</strong> You can reduce the number of round-trips to the database, thereby improving application performance, by grouping multiple UPDATE, DELETE, or INSERT statements into a single batch and having the whole batch sent to the database and processed in one trip. This is especially useful in combination with a prepared statement.</p> </blockquote> <p>As described in <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/ad/tjvbtupd.htm" rel="nofollow noreferrer">IBM's documentation</a> and taken from <a href="https://stackoverflow.com/a/14265302/734687">here</a>:</p> <blockquote> <p>The JDBC drivers that support JDBC 2.0 and above support batch updates. With batch updates, instead of updating rows of a DB2(R) table one at a time, you can direct JDBC to execute a group of updates at the same time. Statements that can be included in the same batch of updates are known as batchable statements.</p> <p><strong>If a statement has input parameters or host expressions, you can include that statement only in a batch that has other instances of the same statement</strong>. This type of batch is known as a <strong>homogeneous batch</strong>. If a statement has no input parameters, you can include that statement in a batch only if the other statements in the batch have no input parameters or host expressions. This type of batch is known as a <strong>heterogeneous batch</strong>. Two statements that can be included in the same batch are known as batch compatible.</p> </blockquote> <p>This means that your request is not possible. The only advantage you can get is performance improvement of batching the same type of statements AND preparing only once:</p> <p>When you execute a single SQL statement the database performs the following actions:</p> <ul> <li>prepare the statement</li> <li>bind the parameters</li> <li>execute the statement</li> </ul> <p>When you use batch commands the following happens:</p> <ul> <li>prepare the statement (all received in a single transmission)</li> <li>for all following identical statements with different parameters <ul> <li>bind the parameters</li> <li>execute the statement</li> </ul></li> </ul> <p>Since the preparation is performed only once you save time.</p> <p>But you can sort and split the commands:</p> <pre><code>sql.withBatch(20, "insert into t1 values(:a, :b)") { ... } sql.withBatch(20, "insert into t2 values(:c)") { ... } </code></pre> <p>BTW, what will compile is</p> <pre><code>sql.withBatch {ps -&gt; ps.addBatch("insert into t1 values(1, 2)") ps.addBatch("insert into t2 values(3)") } </code></pre> <p>But in this case I am curious what will happen: I expect that the JDBC driver will simply not use batching.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload