tsx:dbconnect tag JSP syntax
Use the <tsx:dbconnect> tag to specify information needed to make a connection to a JDBC or an ODBC database.
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 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>
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.
- url and driver
Respresents a required attribute if you want to establish a database connection. You must provide the URL and driver.
The appserver supports connection to JDBC databases and ODBC databases.
- For a JDBC database, the URL consists of the following colon-separated elements: jdbc, the subprotocol name, and the name of the database to access. An example for a connection to the Sample database included with IBM DB2 is...url="jdbc:db2:sample" driver="COM.ibm.db2.jdbc.app.DB2Driver"
- For an ODBC database, use the Sun JDBC-to-ODBC bridge driver included in their Java2 Software Developers Kit (SDK) or another vendor's ODBC driver.
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 followsurl="jdbc:odbc:autos" driver="sun.jdbc.odbc.JdbcOdbcDriver"
Note: To enable the appserver 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 appserver 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.
See AlsoJSP files
Webapplications: Resources for learning