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: JSP syntax: Tags for database access

Beginning with IBM WebSphere Application Server Version 3.x, the JSP 1.0 support was extended to provide syntax for database access. The syntax makes it simple to add a database connection to a Web page and then use that connection to query or update the database. The user ID and password for the database connection can be provided by the user at request-time or hard coded within the JSP file.

The table summarizes the tags. Click a tag to link to its syntax description.

Goal Tag Details and examples
Specify information needed to make a connection to a JDBC or an ODBC database. <tsx:dbconnect> The <tsx:dbconnect> syntax does not establish the connection. Instead, the <tsx:dbquery> and <tsx:dbmodify> syntax are used to reference a <tsx:dbconnect> in the same JSP file and establish the connection.

When the JSP file is compiled into a servlet, the Java processor adds the Java coding for the <tsx:dbconnect> syntax to the servlet's service() method, which means a new database connection is created for each request for the JSP file.

Avoid hard coding the user ID and password in the <tsx:dbconnect>. <tsx:userid> and <tsx:passwd> Use the <tsx:userid> and <tsx:passwd> to accept user input for the values and then add that data to the request object. The request object can be accessed by a JSP file (such as the JSPEmployee.jsp example) that requests the database connection.

The <tsx:userid> and <tsx:passwd> must be used within a <tsx:dbconnect> tag.

Establish a connection to a database, submit database queries, and return the results set. <tsx:dbquery>

The <tsx:dbquery>:

  1. References a <tsx:dbconnect> in the same JSP file and uses the information it provides to determine the database URL and driver. The user ID and password are also obtained from the <tsx:dbconnect> if those values are provided in the <tsx:dbconnect>.
  2. Establishes a new connection
  3. Retrieves and caches data in the results object
  4. Closes the connection (releases the connection resource)
Establish a connection to a database and then add records to a database table. <tsx:dbmodify>

The <tsx:dbmodify>:

  1. References a <tsx:dbconnect> in the same JSP file and uses the information provided by that to determine the database URL and driver. The user ID and password are also obtained from the <tsx:dbconnect> if those values are provided in the <tsx:dbconnect>.
  2. Establishes a new connection
  3. Updates a table in the database
  4. Closes the connection (releases the connection resource)

Examples:
Basic example

Display query results. <tsx:repeat> and <tsx:getProperty> The <tsx:repeat> loops through each of the rows in the query results. The <tsx:getProperty> uses the query results object (for the <tsx:dbquery> syntax whose identifier is specified by the <tsx:getProperty> bean attribute) and the appropriate column name (specified by the <tsx:getProperty> property attribute) to retrieve the value.

Note:  You cannot assign the value from the <tsx:getProperty> tag to a variable. The value, generated as output from this tag, is displayed in the Browser window.

Examples:
Basic example

Go to previous article: JSP  syntax: The repeat tag results set and the associated bean Go to next article: JSP syntax: <tsx:dbconnect> tag syntax

 

 
Go to previous article: JSP  syntax: The repeat tag results set and the associated bean Go to next article: JSP syntax: <tsx:dbconnect> tag syntax