InfoCenter Home >
4: Developing applications >
4.2: Building Web applications >
4.2.2: Developing JSP files >
4.2.2.3: Overview of JSP file content >
4.2.2.3.7: IBM extensions to JSP syntax >
4.2.2.3.7.2: JSP syntax: Tags for database access >
4.2.2.3.7.2.1: JSP syntax: <tsx:dbconnect> tag syntax

4.2.2.3.7.2.1: JSP syntax: <tsx:dbconnect> tag syntax

<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

    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 optional, the userid must be provided. See <tsx:userid> and <tsx:passwd> for an alternative to hard coding 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, the password must be provided. See <tsx:userid> and <tsx:passwd> for an alternative to hard coding this attribute in the JSP file.

  • url and driver

    To establish a database connection, the URL and driver must be provided.

    The Application Server Version 3 supports connection to JDBC databases and ODBC databases.

    JDBC database

    For a JDBC database, the URL consists of the following colon-separated elements: jdbc, the sub-protocol name, and the name of the database 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"
    

    ODBC database

    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.

    If the database is an ODBC database, you can use an ODBC driver or 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.
  • 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 <tsx:dbconnect> tag.

An empty element (such as <url></url>) is valid.

Go to previous article: JSP syntax: Tags for database access Go to next article: JSP syntax: <tsx:userid> and <tsx:passwd> tag syntax

 

 
Go to previous article: JSP syntax: Tags for database access Go to next article: JSP syntax: <tsx:userid> and <tsx:passwd> tag syntax