Intermediate JSP Sample : Using the OC4J JSP Tag Library for SQL

Previous Contents Next

Contents

Purpose

Use the SQL Custom Tag Library supplied with OC4J JSP. The sample will demonstrate the following using the SQL tag library with Connection Pooling:

  • Simple Query Nested in dbOpen Tag
  • Result Set Iteration
  • Executing DML Statements
  • Query with XML Output

Remarks

OC4J JSP supplies the SQL Custom Tag Library to simplify the coding effort required to perform database operations from JSPs. These custom tags are prefixed with <sql: and include dbOpen, dbClose, dbQuery, dbCloseQuery, dbNextRow, and dbExecute.

The dbopen tag is used to open a connection to a database. In OC4J Release 2 the dbopen tag, includes a new attribute datasource. The datasource attribute can take the JNDI values for a pooled or a vanilla JDBC connection datasource specified in the data-sources.xml. In this sample, the datasource is set to a pooled JDBC connection thus using Connection Pooling with the SQL Tag.

Code from HotelDetails.jsp

<%-- Define alias for SQL tag library --%>
<%@ taglib uri="sqltaglib.tld" prefix="sql" %> ...
<!-- Open a db connection using the dbOpen tag -->
<sql:dbOpen dataSource="jdbc/PooledOTN9iDS" >
<!--
Execute a query. By default the dbQuery tag returns the
data returned by the query formatted in an HTML Table
if output attribute is not defined
-->
<sql:dbQuery >
SELECT hot.id AS "Hotel Id", hot.name AS "Hotel Name",
hot.address AS "Location", hot.phone AS "Phone",
hot.fax AS "Fax", cit.name AS "City"
FROM hotels hot, cities cit
WHERE hot.id = <%= request.getParameter("HOTEL_ID") %>
AND hot.cty_id = cit.id
ORDER BY hot.name
</sql:dbQuery>
</sql:dbOpen>
...

 

Source Code Listings


Previous Contents Next
E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy