- id
A required identifier for this tag. The scope is the JSP file. This identifier is referenced by the connection attribute of the <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 optional, the userid must be provided. See <USERID> and <PASSWD> for an alternative to hardcoding this information in the JSP file.
- passwd
An optional attribute that specifies the user password for the userid. (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, the password must be provided. See <USERID> and <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. If these attributes are not specified in the <DBCONNECT> tag, the xmlref attribute or the jndiname attribute must be specified.
The Application Server Version 3 supports connection to JDBC databases and ODBC databases. When connecting to an ODBC database, you can use the Sun JDBC-to-ODBC bridge driver included in the Java Development Kit (JDK) 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 be used to establish the database connection.
For a connection to a JDBC database, the URL consists of the following colon-separated elements: jdbc, the sub-protocol name, and the name of the database table to be accessed. 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"
If the database is an ODBC database, you can use an ODBC driver or the the Sun JDBC-to-ODBC bridge included with the JDK. If you want to use an ODBC driver, refer to the driver documentation for instructions on specifying the database location (the url attribute) and the driver name.
In the case of the bridge, the url syntax is jdbc:odbc:database. An example is:
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.
If your JSP accesses a different JDBC or ODBC database than
the one the Application Server uses for its repository, ensure that you add the JDBC or
ODBC driver for the other database to the Application Server's classpath.
-
jndiname
An optional attribute that identifies a valid context in the Application Server 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.
If the jndiname is specified, the JSP processor ignores the driver and url attributes on the
<DBCONNECT> tag or in the file specified by the xmlref tag.
- xmlref
A file (in XML format) that contains the URL, driver, user ID, password information needed for a connection. This mechanism provides Web administrators an alternative method for specifying the user ID and password. It is an alternative to hardcoding the information in a <DBCONNECT> tag or reading the information from the request object parameters. This is useful when third-party vendors develop your JSP files and when you need to make quick changes or test an application with a different data source.
When the JSP compiler processes the <DBCONNECT> tag, it reads all of the specified tag attributes. If any of the required attributes are missing, the compiler checks for an xmlref attribute. If the attribute is specified, the compiler reads the configuration file.
The xmlref takes precedence over the <DBCONNECT> tag. For example, if the <DBCONNECT> tag and the xmlref file include values for the URL and the the driver, the values in the xmlref file are used.
The configuration file can have any filename and extension that is valid for the operating system. Place the file in the same directory as the JSP that contains the referring <DBCONNECT> tag. An example of a configuration file is:
<?xml version="1.0" ?>
<db-info>
<url>jdbc:odbc:autos</url>
<user-id>smith</user-id>
<dbDriver>sun.jdbc.odbc.JdbcOdbcDriver</dbDriver>
<password>v598m</password>
<jndiName>jdbc/demo/sample</jndiName>
</db-info>
All of the elements shown in the example XML file need to be specified. However, an empty element (such as <url></url>) is valid.