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.8: IBM extensions to JSP .91 syntax >
4.2.2.3.8.2: JSP .91 syntax: JSP tags for database access
4.2.2.3.8.2: JSP .91 syntax: JSP tags for database access
The Application Server Version 3.5 extends JSP 0.91 support by providing
a set of tags for database access. These HTML-like tags make 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 hardcoded 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 |
<DBCONNECT> |
The <DBCONNECT> tag does not establish the connection.
Instead, the <DBQUERY> and <DBMODIFY> tags are used to reference a
<DBCONNECT> tag 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 <DBCONNECT> tag to the servlet's service()
method, which means a new database connection is created for each request for
the JSP file.
Examples:
Employee.jsp example
|
Avoid hard coding the user ID and password in the <DBCONNECT> tag |
<USERID> and <PASSWD> |
Use the <USERID> and <PASSWD> tags to accept user input for the
values and then add that data to the request object where it can be accessed by a
JSP file (such as the Employee.jsp example) that requests the database connection.
The <USERID> and <PASSWD> tags must be used within a <DBCONNECT>
tag.
Examples:
None
|
Establish a connection to a database, submit database queries, and return the results set. |
<DBQUERY> |
The <DBQUERY> tag:
- References a <DBCONNECT> tag in the same JSP file and uses the information provided by that tag to determine the database URL and driver. The user ID and password are also obtained from the <DBCONNECT> tag if those values are provided in the <DBCONNECT> tag.
- Establishes a new connection
- Retrieves and caches data in the results object
- Closes the connection (releases the connection resource)
Examples:
Basic example
Employee.jsp
EmployeeRepeatResults.jsp
|
Establish a connection to a database and then add records to a database table. |
<DBMODIFY> |
The <DBMODIFY> tag:
- References a <DBCONNECT> tag in the same JSP file and
uses the information provided by that tag to determine the database
URL and driver. The user ID and password are also obtained from the <DBCONNECT> tag if those values are provided in the <DBCONNECT> tag.
- Establishes a new connection
- Updates a table in the database
- Closes the connection (releases the connection resource)
Examples:
Basic example
EmployeeRepeatResults.jsp
|
Display query results |
<REPEAT> and <INSERT> tags |
The <REPEAT> tag loops through each of the rows in the query results.
The <INSERT> tag uses the query results object (for the <DBQUERY>
tag whose identifier is specified by the <INSERT> bean attribute) and the
appropriate column name (specified by the <INSERT> property attribute) to
retrieve the value.
Examples:
Basic example
|
|
|