This section assumes familiarity with databases and the
Java
Database Connectivity
(JDBC) framework, which is briefly introduced by the
Core
JSF textbook in chapter 12.
We will also cover databases and JDBC independently in a different
lecture.
Databases that use the
Structured Query Language (SQL) organize
data in tables and also return query results in tables.
Thus SQL query results are a natural fit for JSF data tables.
When working with a database, the
value attribute
for
h:dataTable is an instance of either:
- java.sql.ResultSet, or
- javax.servlet.jsp.jstl.Result
If using
java.sql.ResultSet,
- The object should not be one
directly returned by Statement.executeQuery (for reasons having
to do with database connections)
- Instead, the object should be wrapped in
a javax.sql.rowset.CachedRowSet object
The
database example application uses the
java.sql.ResultSet approach.