com.evanmclean.evlib.velocity
Class ResultSetMethodizer
java.lang.Object
com.evanmclean.evlib.velocity.AbstractResultSetMethodizer
com.evanmclean.evlib.velocity.ResultSetMethodizer
- All Implemented Interfaces:
- Iterator<AbstractResultSetMethodizer.Row>
public class ResultSetMethodizer
- extends AbstractResultSetMethodizer
A wrapper around a JDBC ResultSet that allows Velocity templates to access
the columns in a template friendly way.
If you had a result set based on the following SQL statement:
SELECT user_id, first_name, surname
FROM users
And you add the result set to your context, wrapped in this methodizer, such
as:
context.put("query", new ResultSetMethodizer(result_set));
Then in your velocity template you could access it like this:
#foreach( $row in $query )
The ID for $row.FirstName $row.Surname is $row.UserId
#end
Note that the result set must remain open while the template is merged. If
you want a version that stores the results so you can close it immediately,
use RowSetMethodizer
.
See AbstractResultSetMethodizer.getPropertyNames(String)
for details
on how column names are mapped to property names by default.
- Author:
- Evan McLean McLean Computer Services (see the
overview for copyright and licensing.)
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ResultSetMethodizer
public ResultSetMethodizer(ResultSet rs)
throws SQLException
- Throws:
SQLException
hasNext
public boolean hasNext()
next
public AbstractResultSetMethodizer.Row next()