open class RowCountCallbackHandler : RowCallbackHandler
Implementation of RowCallbackHandler. Convenient superclass for callback handlers. An instance can only be used once.
We can either use this on its own (for example, in a test case, to ensure that our result sets have valid dimensions), or use it as a superclass for callback handlers that actually do something, and will benefit from the dimension information it provides.
A usage example with JdbcTemplate:
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); // reusable object RowCountCallbackHandler countCallback = new RowCountCallbackHandler(); // not reusable jdbcTemplate.query("select * from user", countCallback); int rowCount = countCallback.getRowCount();
Author
Rod Johnson
Since
May 3, 2001
RowCountCallbackHandler()
Implementation of RowCallbackHandler. Convenient superclass for callback handlers. An instance can only be used once. We can either use this on its own (for example, in a test case, to ensure that our result sets have valid dimensions), or use it as a superclass for callback handlers that actually do something, and will benefit from the dimension information it provides. A usage example with JdbcTemplate:
|
fun getColumnCount(): Int
Return the number of columns in this result set. Valid once we've seen the first row, so subclasses can use it during processing |
|
fun getColumnNames(): Array<String>
Return the names of the columns. Valid after processRow is invoked the first time. |
|
fun getColumnTypes(): IntArray
Return the types of the columns as java.sql.Types constants Valid after processRow is invoked the first time. |
|
fun getRowCount(): Int
Return the row count of this ResultSet Only valid after processing is complete |
|
fun processRow(rs: ResultSet): Unit
Implementation of ResultSetCallbackHandler. Work out column size if this is the first row, otherwise just count rows. Subclasses can perform custom extraction or processing by overriding the |