Network Deployment (Distributed operating systems), v8.0 > Reference > Developer detailed usage information
tsx:dbconnect tag JSP syntax (deprecated)
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.
Support for tsx tags in the JSP engine are deprecated in WAS v6.0. Instead of using the tsx tags, you should use equivalent tags from the JSP Standard Tag Library (JSTL).
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>where:
- id
Represents a required identifier. The scope is the JSP file. This identifier is referenced by the connection attribute of a <tsx:dbquery> tag.
- userid
Represents an optional attribute that specifies a valid user ID for the database 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.
- passwd
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. We must provide the URL and driver.
The application server 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 follows:
url="jdbc:odbc:autos" driver="sun.jdbc.odbc.JdbcOdbcDriver"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.
- jndiname
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.
JSP
Use installed optional packages
Manage shared libraries
Related
Web applications: Resources for learning