Java Reference
In-Depth Information
After dropping the DB Report item into our page, we get a window that is very
similar to the one we get when dropping the DB Query item. After entering values for
the Variable Name , Scope , Data Source , and Query Statement fields, the following
markup is generated in the location where we dropped the DB Report item.
<sql:query var="result" dataSource="jdbc/sample">
SELECT name, city, state FROM customer
</sql:query>
<table border="1">
<!-- column headers -->
<tr>
<c:forEach var="columnName"
items="${result.columnNames}">
<th><c:out value="${columnName}"/></th>
</c:forEach>
</tr>
<!-- column data -->
<c:forEach var="row" items="${result.rowsByIndex}">
<tr>
<c:forEach var="column" items="${row}">
<td><c:out value="${column}"/></td>
</c:forEach>
</tr>
</c:forEach>
</table>
Notice that the generated <c:forEach> tags dynamically generate the table header
by invoking the getColumNames() method of the javax.servlet.jsp.jstl.
sql.Result interface as a JavaBean property. Similarly, the bi-dimensional array
returned by the getRowsByIndex() method is used to traverse the result set and
display its contents on the page.
Modifying database data with the
<sql:update> tag
The JSTL <sql:update> tag allows us to modify database data either through SQL
INSERT , UPDATE , or DELETE statements. Just like other JSTL tags we have discussed
so far, the easiest way to use this tag with NetBeans is to drag the appropriate item
from the NetBeans palette into our page.
 
Search WWH ::




Custom Search