<tsx:dbconnect>
Use the <tsx:dbconnect> syntax to specify information needed to make a connection to a JDBC-accessible database. The <tsx:dbconnect> syntax does not establish the connection. Instead, the <tsx:dbquery> and <tsx:dbmodify> syntax are used to reference a <tsx:dbconnect> in the same JSP file and establish the connection.
When the JSP file is compiled into a servlet, the Java processor adds the Java coding for the <tsx:dbconnect> syntax to the servlet's service() method, which means a new database connection is created for each request for the JSP file.
The <tsx:dbconnect> syntax is:
<tsx:dbconnect id="connection_id" userid="db_user" passwd="user_password" url="jdbc:subprotocol:database" driver="database_driver_name" jndiname="JNDI_context/logical name"> </tsx:dbconnect>The following list describes the attributes and their values:
id
A required identifier. The scope is the JSP file. This identifier is referenced by the connection attribute of a <tsx:dbquery> tag.userid
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.Although the userid attribute is an optional tag attribute, provide a user ID for this tag, either with the attribute or by using the nested tag <tsx:userid>. See <tsx:userid> and <tsx:passwd> for an alternative to hardcoding this information in the JSP file.
passwd
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.Although the passwd attribute is optional, provide a password for this tag, either with the attribute or by using the <tsx:passwd> tag. See <tsx:userid> and <tsx:passwd> for an alternative to hardcoding this attribute in the JSP file.
url and driver
To establish a database connection, the URL and driver must be provided.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.
For a connection to a JDBC-accessible database, the URL consists of the following colon-separated elements: jdbc, the subprotocol name, and the name of the database to be accessed. For example:
url="jdbc:db2:*local" driver="com.ibm.db2.jdbc.app.DB2Driver"jndiname
This optional attribute identifies a valid context in the WAS JNDI naming context and the logical name of the data source in that context. The context is configured by the Web administrator using and administrative client such as the administrative console.
All of the elements shown in the example need to be specified. However, an empty element (such as <url></url>) is valid.
When the JSP file is compiled into a servlet, the Java processor adds the Java coding for the <tsx:dbconnect> syntax to the servlet's service() method, which means a new database connection is created for each request for the JSP file.