ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzatz_5.4.0.1/51/program/jspmod.htm

79 lines
3.2 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<LINK rel="stylesheet" type="text/css" href="../../../rzahg/ic.css">
<title>&lt;tsx:dbmodify&gt;</title>
</head>
<BODY>
<!-- Java sync-link -->
<SCRIPT LANGUAGE="Javascript" SRC="../../../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
<h5><a name="jspmod"></a>&lt;tsx:dbmodify&gt;</h5>
<p>Use the &lt;tsx:dbmodify&gt; syntax to establish a connection to a database and then add records to a database table.</p>
<p>The &lt;tsx:dbmodify&gt; tag:</p>
<ul>
<li>Refers to a &lt;tsx:dbconnect&gt; in the same JSP file and uses the information provided by that database connection to determine the database URL and driver. The user ID and password are also obtained from the &lt;tsx:dbconnect&gt; if those values are provided in the &lt;tsx:dbconnect&gt;.</li>
<li>Establishes a new connection.</li>
<li>Updates a table in the database.</li>
<li>Closes the connection (releases the connection resource).</li>
</ul>
<p>The &lt;tsx:dbmodify&gt; syntax is:</p>
<pre>&lt;tsx:dbmodify connection=&quot;<em>connection_id</em>&quot; &gt;
&lt;!-- Any valid database update commands can be -&gt;
&lt;!-- placed within the tsx:dbmodify tag. Any other -&gt;
&lt;!-- syntax, including HTML comments, are not valid. -&gt;
&lt;/tsx:dbmodify&gt;</pre>
<p>This list describes the attributes and their values:</p>
<ul>
<li><p><strong>connection</strong>
<br>The identifier of a &lt;tsx:dbconnect&gt; in this JSP file. That &lt;tsx:dbconnect&gt; provides the database URL, driver name, and (optionally) the user ID and password for the connection.</p></li>
<li><p><em>Database commands</em>
<br>For more information about database commands, see this resource:</p>
<ul>
<li><a href="../../../icbase/db2/v5r2rbafzmst02.htm" target="_blank">DB2 Universal Database for iSeries SQL Reference (V5R2)</a></li>
<li><a href="../../../icbase/db2/v5r3rbafzmst02.htm" target="_blank">DB2 Universal Database for iSeries SQL Reference (V5R3)</a></li>
</ul></li>
</ul>
<p>In the following example, a new employee record is added to a database. The values of the fields are based on user input from this JSP and referenced in the database commands using the &lt;tsx:getProperty&gt; tag.</p>
<pre>&lt;% String empno = request.getParameter(&quot;EMPNO&quot;); %&gt;
&lt;% String firstnme = request.getParameter(&quot;FIRSTNME&quot;); %&gt;
&lt;% String midinit = request.getParameter(&quot;MIDINIT&quot;); %&gt;
&lt;% String lastname = request.getParameter(&quot;LASTNAME&quot;); %&gt;
&lt;% String workdept = request.getParameter(&quot;WORKDEPT&quot;); %&gt;
&lt;% String edlevel = request.getParameter(&quot;EDLEVEL&quot;); %&gt;
&lt;tsx:dbmodify connection=&quot;conn&quot; &gt;
INSERT INTO WSDEMO.EMPLOYEE
(EMPNO,FIRSTNME,MIDINIT,LASTNAME,WORKDEPT,EDLEVEL)
VALUES
( '&lt;%=empno%&gt;',
'&lt;%=firstnme%&gt;',
'&lt;%=midinit%&gt;',
'&lt;%=lastname%&gt;',
'&lt;%=workdept%&gt;',
&lt;%=edlevel%&gt; )
&lt;/tsx:dbmodify&gt;</pre>
</body>
</html>