background image

SQL Tag Library

<< Formatting Tags | The transaction Tag >>
<< Formatting Tags | The transaction Tag >>

SQL Tag Library

SQL Tag Library
The JSTL SQL tags for accessing databases listed in
Table 7­7
are designed for quick
prototyping and simple applications. For production applications, database operations are
normally encapsulated in JavaBeans components.
TABLE 7­7
SQL Tags
Area
Function
Tags
Prefix
Database
Setting the data source
setDataSource
sql
SQL
query
dateParam
param
transaction
update
dateParam
param
The setDataSource tag allows you to set data source information for the database. You can
provide a JNDI name or DriverManager parameters to set the data source information. All of
the Duke's Bookstore pages that have more than one SQL tag use the following statement to set
the data source:
<sql:setDataSource dataSource=
"jdbc/BookDB" />
The query tag performs an SQL query that returns a result set. For parameterized SQL queries,
you use a nested param tag inside the query tag.
In tut-install/javaeetutorial5/examples/web/bookstore4/web/books/bookcatalog.jsp,
the value of the Add request parameter determines which book information should be retrieved
from the database. This parameter is saved as the attribute name bid and is passed to the param
tag.
<c:set var=
"bid" value="${param.Add}"/>
<sql:query var=
"books" >
select * from PUBLIC.books where id = ?
<sql:param value=
"${bid}" />
</sql:query>
The update tag is used to update a database row. The transaction tag is used to perform a
series of SQL statements atomically.
The JSP page
tut-install/javaeetutorial5/examples/web/bookstore4/web/books/bookreceipt.jsp uses
SQL Tag Library
The Java EE 5 Tutorial · September 2007
218