Java Reference
In-Depth Information
<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.
Inserting Database Data
To execute an
INSERT
statement, we can drag the
DB Insert
item from the NetBeans
palette into our page.