71 lines
5.1 KiB
HTML
71 lines
5.1 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE html
|
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html lang="en-us" xml:lang="en-us">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="security" content="public" />
|
|
<meta name="Robots" content="index,follow" />
|
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
|
<meta name="DC.Type" content="reference" />
|
|
<meta name="DC.Title" content="PreparedStatement batch update" />
|
|
<meta name="abstract" content="A preparedStatement batch is similar to the Statement batch; however, a preparedStatement batch always works off the same prepared statement, and you only change the parameters to that statement." />
|
|
<meta name="description" content="A preparedStatement batch is similar to the Statement batch; however, a preparedStatement batch always works off the same prepared statement, and you only change the parameters to that statement." />
|
|
<meta name="DC.Relation" scheme="URI" content="batchupd.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="batchstm.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="batchexc.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="batchblo.htm" />
|
|
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
|
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
|
|
<meta name="DC.Format" content="XHTML" />
|
|
<meta name="DC.Identifier" content="batchpre" />
|
|
<meta name="DC.Language" content="en-us" />
|
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
|
<!-- US Government Users Restricted Rights -->
|
|
<!-- Use, duplication or disclosure restricted by -->
|
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
|
<title>PreparedStatement batch update</title>
|
|
</head>
|
|
<body id="batchpre"><a name="batchpre"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">PreparedStatement batch update</h1>
|
|
<div><p>A preparedStatement batch is similar to the Statement batch; however,
|
|
a preparedStatement batch always works off the same prepared statement, and
|
|
you only change the parameters to that statement.</p>
|
|
<div class="section"><p>The following is an example that uses a preparedStatement batch.</p>
|
|
<div class="note"><span class="notetitle">Note:</span> Read
|
|
the <a href="codedisclaimer.htm">Code example disclaimer</a> for important
|
|
legal information.</div>
|
|
<blockquote><pre>connection.setAutoCommit(false);
|
|
PreparedStatement statement =
|
|
connection.prepareStatement("INSERT INTO TABLEX VALUES(?, ?)");
|
|
statement.setInt(1, 1);
|
|
statement.setString(2, "Cujo");
|
|
statement.addBatch();
|
|
statement.setInt(1, 2);
|
|
statement.setString(2, "Fred");
|
|
statement.addBatch();
|
|
statement.setInt(1, 3);
|
|
statement.setString(2, "Mark");
|
|
statement.addBatch();
|
|
int [] counts = statement.executeBatch();
|
|
connection.commit();</pre>
|
|
</blockquote>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="batchupd.htm" title="Batch update support allows any updates to the database to be passed as a single transaction between the user program and the database. This procedure can significantly improve performance when many updates must be performed at once.">Batch updates</a></div>
|
|
</div>
|
|
<div class="relconcepts"><strong>Related concepts</strong><br />
|
|
<div><a href="batchexc.htm" title="An important consideration of batch updates is what action to take when a call to the executeBatch method fails. In this case, a new type of exception, called BatchUpdateException, is thrown. The BatchUpdateException is a subclass of SQLException and it allows you to call all the same methods you have always called to receive the message, the SQLState, and vendor code.">BatchUpdateException</a></div>
|
|
<div><a href="batchblo.htm" title="You can use a blocked insert is an iSeries operation to insert several rows into a database table at a time.">Blocked insert support</a></div>
|
|
</div>
|
|
<div class="relref"><strong>Related reference</strong><br />
|
|
<div><a href="batchstm.htm" title="To perform a Statement batch update, you must turn off auto-commit. In Java Database Connectivity (JDBC), auto-commit is on by default. Auto-commit means any updates to the database are committed after each SQL statement is processed. If you want to treat a group of statements being handed to the database as one functional group, you do not want the database committing each statement individually. If you do not turn off auto-commit and a statement in the middle of the batch fails, you cannot roll back the entire batch and try it again because half of the statements have been made final. Further, the additional work of committing each statement in a batch creates a lot of overhead.">Statement batch update</a></div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |