ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzaha_5.4.0.1/prepproc.htm

79 lines
6.1 KiB
HTML
Raw Permalink Normal View History

2024-04-02 14:02:31 +00:00
<?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="concept" />
<meta name="DC.Title" content="Process PreparedStatements" />
<meta name="abstract" content="Processing SQL statements with a PreparedStatement object is accomplished with the executeQuery, executeUpdate, and execute methods like Statement objects are processed. Unlike Statement versions, no parameters are passed on these methods because the SQL statement was already provided when the object was created. Because PreparedStatement extends Statement, applications can attempt to call versions of executeQuery, executeUpdate, and execute methods that take a SQL statement. Doing so results in an SQLException being thrown." />
<meta name="description" content="Processing SQL statements with a PreparedStatement object is accomplished with the executeQuery, executeUpdate, and execute methods like Statement objects are processed. Unlike Statement versions, no parameters are passed on these methods because the SQL statement was already provided when the object was created. Because PreparedStatement extends Statement, applications can attempt to call versions of executeQuery, executeUpdate, and execute methods that take a SQL statement. Doing so results in an SQLException being thrown." />
<meta name="DC.Relation" scheme="URI" content="prepstat.htm" />
<meta name="DC.Relation" scheme="URI" content="prepcreate.htm" />
<meta name="DC.Relation" scheme="URI" content="prepex.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="prepproc" />
<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>Process PreparedStatements</title>
</head>
<body id="prepproc"><a name="prepproc"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Process PreparedStatements</h1>
<div><p>Processing SQL statements with a PreparedStatement object is accomplished
with the executeQuery, executeUpdate, and execute methods like Statement objects
are processed. Unlike Statement versions, no parameters are passed on these
methods because the SQL statement was already provided when the object was
created. Because PreparedStatement extends Statement, applications can attempt
to call versions of executeQuery, executeUpdate, and execute methods that
take a SQL statement. Doing so results in an SQLException being thrown.</p>
<div class="section"><h4 class="sectiontitle">Return results from SQL queries</h4><p>If an SQL query
statement that returns a ResultSet object is to be processed, the executeQuery
method should be used. The <a href="prepex.htm">PreparedStatementExample</a> program
uses a PreparedStatement object's executeQuery method to obtain a ResultSet.</p>
<div class="note"><span class="notetitle">Note:</span> If
an SQL statement processed with the executeQuery method does not return a
ResultSet, an SQLException is thrown.</div>
</div>
<div class="section"><h4 class="sectiontitle">Return update counts for SQL statements</h4><p>If the SQL
is known to be a Data Definition Language (DDL) statement or a Data Manipulation
Language (DML) statement that returns an update count, the executeUpdate method
should be used. The <a href="prepex.htm">PreparedStatementExample</a> sample
program uses a PreparedStatement object's executeUpdate method.</p>
</div>
<div class="section"><h4 class="sectiontitle">Process SQL statements where the expected return is unknown</h4><p>If
the SQL statement type is not known, the execute method should be used. Once
this method has been processed, the JDBC driver can tell the application what
results types the SQL statement generated through API calls. The execute method
returns true if the result is at least one ResultSet and false if the return
value is an update count. Given this information, applications can use the
getUpdateCount or getResultSet statement methods to retrieve the return value
from processing the SQL statement.</p>
<p><strong>Note:</strong> Calling the getUpdateCount
method when the result is a ResultSet returns -1. Calling the getResultSet
method when the result is an update count returns null.</p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="prepstat.htm" title="PreparedStatements extend the Statement interface and provide support for adding parameters to SQL statements.">PreparedStatements</a></div>
</div>
<div class="relconcepts"><strong>Related concepts</strong><br />
<div><a href="prepcreate.htm" title="The prepareStatement method is used to create new PreparedStatement objects. Unlike the createStatement method, the SQL statement must be supplied when the PreparedStatement object is created. At that time, the SQL statement is precompiled for use.">Create and use PreparedStatements</a></div>
</div>
<div class="relref"><strong>Related reference</strong><br />
<div><a href="prepex.htm" title="This is an example of using a PreparedStatement object's executeQuery method to obtain a ResultSet.">Example: Use PreparedStatement to obtain a ResultSet</a></div>
</div>
</div>
</body>
</html>