ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzamy_5.4.0.1/50/program/jspcon.htm

65 lines
4.1 KiB
HTML
Raw Permalink Normal View History

2024-04-02 14:02:31 +00:00
<!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:dbconnect&gt;</title>
</head>
<BODY>
<!-- Java sync-link -->
<SCRIPT LANGUAGE="Javascript" SRC="../../../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
<h5><a name="jspcon"></a>&lt;tsx:dbconnect&gt;</h5>
<p>Use the &lt;tsx:dbconnect&gt; syntax to specify information needed to make a connection to a JDBC-accessible database. The &lt;tsx:dbconnect&gt; syntax does not establish the connection. Instead, the &lt;tsx:dbquery&gt; and &lt;tsx:dbmodify&gt; syntax are used to reference a &lt;tsx:dbconnect&gt; in the same JSP file and establish the connection.</p>
<p>When the JSP file is compiled into a servlet, the Java processor adds the Java coding for the &lt;tsx:dbconnect&gt; syntax to the servlet's service() method, which means a new database connection is created for each request for the JSP file.</p>
<p>The &lt;tsx:dbconnect&gt; syntax is:</p>
<pre>&lt;tsx:dbconnect id=&quot;<em>connection_id</em>&quot; userid=&quot;<em>db_user</em>&quot; passwd=&quot;<em>user_password</em>&quot;
url=&quot;jdbc:<em>subprotocol</em>:<em>database</em>&quot; driver=&quot;<em>database_driver_name</em>&quot;
jndiname=&quot;<em>JNDI_context/logical name</em>&quot;&gt;
&lt;/tsx:dbconnect&gt;</pre>
<p>This describes the attributes and their values:</p>
<ul>
<li><p><strong>id</strong>
<br>A required identifier. The scope is the JSP file. This identifier is referenced by the connection attribute of a &lt;tsx:dbquery&gt; tag.</p></li>
<li><p><strong>userid</strong>
<br>An optional attribute that specifies a valid user ID for the database to be accessed. If specified, this attribute and its value are added to the request object.</p>
<p>Although the userid attribute is an optional tag attribute, you must provide a user ID for this tag, either with the attribute or by using the nested tag &lt;tsx:userid&gt;. See <a href="jspidp.htm">&lt;tsx:userid&gt; and &lt;tsx:passwd&gt;</a> for an alternative to hardcoding this information in the JSP file.</p></li>
<li><p><strong>passwd</strong>
<br>An optional attribute that specifies the user password for the userid attribute. (This attribute is not optional if the userid attribute is specified.) If specified, this attribute and its value are added to the request object.</p>
<p>Although the passwd attribute is optional, you must provide a password for this tag, either with the attribute or by using the &lt;tsx:passwd&gt; tag. See <a href="jspidp.htm">&lt;tsx:userid&gt; and &lt;tsx:passwd&gt;</a> for an alternative to hardcoding this attribute in the JSP file.</p></li>
<li><p><strong>url</strong> and <strong>driver</strong>
<br>To establish a database connection, the URL and driver must be provided.</p>
<p>The url attribute specifies the location of the database. The driver attribute specifies the name of the driver to be used to establish the database connection.</p>
<p>For a connection to a JDBC-accessible database, the URL consists of these colon-separated elements: jdbc, the subprotocol name, and the name of the database to be accessed. For example:</p>
<pre>url=&quot;jdbc:db2:*local&quot;
driver=&quot;com.ibm.db2.jdbc.app.DB2Driver&quot;</pre></li>
<li><p><strong>jndiname</strong>
<br>This optional attribute identifies a valid context in the WebSphere Application Server - Express JNDI naming context and the logical name of the data source in that context. The context is configured by the Web administrator using an administrative client such as the WebSphere administrative console.</p></li>
</ul>
<p>All of the elements shown in the example need to be specified. However, an empty element (such as &lt;url&gt;&lt;/url&gt;) is valid.</p>
<p>When the JSP file is compiled into a servlet, the Java processor adds the Java coding for the &lt;tsx:dbconnect&gt; syntax to the servlet's service() method, which means a new database connection is created for each request for the JSP file.</p>
</body>
</html>