After entering the resource name for our datasource, saving, then clicking on OK , we
can see it listed in the Resource References section of our application's web.xml .
At this point we are ready to use the JSTL SQL library.
Retrieving database data with the <sql:query>
The first JSTL SQL tag that we will cover is the <sql:query> tag. This tag allows us
to execute an SQL SELECT statement, and store it in an object implementing the
javax.servlet.jsp.jstl.sql.Result interface. We can then iterate through this
object with the standard JSTL <c:forEach> tag.
The javax.servlet.jsp.jstl.sql.Result interface defines a number of methods
that we can call from a <c:forEach> tag in order to display database data on the
page. These methods are outlined in the following table:
Returns an array of String objects containing the column
names in the result set.
Returns an int indicating the number of rows in the result
Returns an array of java.util.SortedMap objects. Each
element in the array represents a row in the result set. Keys in
each SortedMap are String objects containing the column
names, values are objects representing the value for the
column in the current row.