background image

query Tag Result Interface

<< The transaction Tag | The Row Interface >>
<< The transaction Tag | The Row Interface >>

query Tag Result Interface

</sql:update>
</c:forEach>
</c:forEach>
<h3><fmt:message key=
"ThankYou"/>
${param.cardname}.</h3><br>
</c:if>
</sql:transaction>
query
Tag Result Interface
The Result interface is used to retrieve information from objects returned from a query tag.
public interface Result
public String[] getColumnNames();
public int getRowCount()
public Map[] getRows();
public Object[][] getRowsByIndex();
public boolean isLimitedByMaxRows();
For complete information about this interface, see the API documentation for the
JSTL
packages.
The var attribute set by a query tag is of type Result. The getRows method returns an array of
maps that can be supplied to the items attribute of a forEach tag. The JSTL expression language
converts the syntax ${result.rows} to a call to result.getRows. The expression ${books.rows}
in the following example returns an array of maps.
When you provide an array of maps to the forEach tag, the var attribute set by the tag is of type
Map
. To retrieve information from a row, use the get("colname") method to get a column value.
The JSP expression language converts the syntax ${map.colname} to a call to
map.get("colname"). For example, the expression ${book.title} returns the value of the title
entry of a book map.
The Duke's Bookstore page
tut-install/javaeetutorial5/examples/web/bookstore4/web/books/bookdetails.jsp
retrieves the column values from the book map as follows.
<c:forEach var=
"book" begin="0" items="${books.rows}">
<h2>${book.title}</h2>
&nbsp;<fmt:message key=
"By"/> <em>${book.firstname}
${book.surname}</em>&nbsp;&nbsp;
(${book.year})<br> &nbsp; <br>
<h4><fmt:message key=
"Critics"/></h4>
<blockquote>${book.description}</blockquote>
<h4><fmt:message key=
"ItemPrice"/>:
<fmt:formatNumber value=
"${book.price}" type="currency"/>
SQL Tag Library
The Java EE 5 Tutorial · September 2007
220