Use the <tsx:dbconnect> tag to specify information needed to make a connection to a database through Java DataBase Connectivity (JDBC) or Open Database Connectivity (ODBC) technology.
The <tsx:dbconnect> syntax does not establish the connection. Use the <tsx:dbquery> and <tsx:dbmodify> syntax instead to reference a <tsx:dbconnect> tag in the same JavaServer Pages (JSP) file to establish the connection.
When the JSP file compiles into a servlet, the Java processor adds the Java coding for the <tsx:dbconnect> syntax to the servlet service() method, which means a new database connection is created for each request for the JSP file.
This section describes the syntax of the <tsx:dbconnect> tag.
<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>
where:
Represents a required identifier. The scope is the JSP file. This identifier is referenced by the connection attribute of a <tsx:dbquery> tag.
Represents an optional attribute that specifies a valid user ID for the database that you want to access. Specify this attribute to add the attribute and its value to the request object.
Although the userid attribute is optional, provide the user ID. See <tsx:userid> and <tsx:passwd> for an alternative to hard coding this information in the JSP file.
Represents an optional attribute that specifies the user password for the userid attribute. (This attribute is not optional if the userid attribute is specified.) If you specify this attribute, the attribute and its value are added to the request object.
Although the passwd attribute is optional, provide the password. See <tsx:userid> and <tsx:passwd> for an alternative to hard coding this attribute in the JSP file.
Respresents a required attribute if you want to establish a database connection. You must provide the URL and driver.
The application server supports connection to JDBC databases and ODBC databases.
url="jdbc:db2:sample" driver="com.ibm.db2.jdbc.app.DB2Driver"
The url attribute specifies the location of the database. The driver attribute specifies the name of the driver to use in establishing the database connection.
If the database is an ODBC database, you can use an ODBC driver or the Sun JDBC-to-ODBC bridge. If you want to use an ODBC driver, refer to the driver documentation for instructions on specifying the database location with the url attribute and the driver name.
If you use the bridge, the url syntax is jdbc:odbc:database. An example follows:
url="jdbc:odbc:autos" driver="sun.jdbc.odbc.JdbcOdbcDriver"
Note: To enable the application server to access the ODBC database, use the ODBC Data Source Administrator to add the ODBC data source to the System DSN configuration. To access the ODBC Administrator, click the ODBC icon on the Windows NT Control Panel.
Represents an optional attribute that identifies a valid context in the application server Java Naming and Directory Interface (JNDI) naming context and the logical name of the data source in that context. The Web administrator configures the context using an administrative client such as the WebSphere Administrative Console.
If you specify the jndiname attribute, the JSP processor ignores the driver and url attributes on the <tsx:dbconnect> tag.
An empty element (such as <url></url>) is valid.
Related concepts
JavaServer Pages