|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.springframework.jdbc.core.RowCountCallbackHandler
public class 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:
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); // reusable object
RowCountCallbackHandler countCallback = new RowCountCallbackHandler(); // not reusable
jdbcTemplate.query("select * from user", countCallback);
int rowCount = countCallback.getRowCount();
| Constructor Summary | |
|---|---|
RowCountCallbackHandler()
|
|
| Method Summary | |
|---|---|
int |
getColumnCount()
Return the number of columns in this result set. |
String[] |
getColumnNames()
Return the names of the columns. |
int[] |
getColumnTypes()
Return the types of the columns as java.sql.Types constants Valid after processRow is invoked the first time. |
int |
getRowCount()
Return the row count of this ResultSet Only valid after processing is complete |
void |
processRow(ResultSet rs)
Implementation of ResultSetCallbackHandler. |
protected void |
processRow(ResultSet rs,
int rowNum)
Subclasses may override this to perform custom extraction or processing. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public RowCountCallbackHandler()
| Method Detail |
|---|
public final void processRow(ResultSet rs)
throws SQLException
Subclasses can perform custom extraction or processing
by overriding the processRow(ResultSet, int) method.
processRow in interface RowCallbackHandlerrs - the ResultSet to process (pre-initialized for the current row)
SQLException - if a SQLException is encountered getting
column values (that is, there's no need to catch SQLException)processRow(java.sql.ResultSet, int)
protected void processRow(ResultSet rs,
int rowNum)
throws SQLException
rs - ResultSet to extract data from. This method is
invoked for each rowrowNum - number of the current row (starting from 0)
SQLExceptionpublic final int[] getColumnTypes()
public final String[] getColumnNames()
public final int getRowCount()
public final int getColumnCount()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||