Package org.springframework.jdbc.core
Class RowCountCallbackHandler
java.lang.Object
org.springframework.jdbc.core.RowCountCallbackHandler
- All Implemented Interfaces:
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();
- Since:
- May 3, 2001
- Author:
- Rod Johnson
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal int
Return the number of columns in this result set.final String[]
Return the names of the columns.final int[]
Return the types of the columns as java.sql.Types constants Valid after processRow is invoked the first time.final int
Return the row count of this ResultSet.final void
processRow
(ResultSet rs) Implementation of ResultSetCallbackHandler.protected void
processRow
(ResultSet rs, int rowNum) Subclasses may override this to perform custom extraction or processing.
-
Constructor Details
-
RowCountCallbackHandler
public RowCountCallbackHandler()
-
-
Method Details
-
processRow
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
processRow(ResultSet, int)
method.- Specified by:
processRow
in interfaceRowCallbackHandler
- Parameters:
rs
- the ResultSet to process (pre-initialized for the current row)- Throws:
SQLException
- if an SQLException is encountered getting column values (that is, there's no need to catch SQLException)- See Also:
-
processRow
Subclasses may override this to perform custom extraction or processing. This class's implementation does nothing.- Parameters:
rs
- the ResultSet to extract data from. This method is invoked for each rowrowNum
- number of the current row (starting from 0)- Throws:
SQLException
-
getColumnTypes
Return the types of the columns as java.sql.Types constants Valid after processRow is invoked the first time.- Returns:
- the types of the columns as java.sql.Types constants. Indexed from 0 to n-1.
-
getColumnNames
Return the names of the columns. Valid after processRow is invoked the first time.- Returns:
- the names of the columns. Indexed from 0 to n-1.
-
getRowCount
public final int getRowCount()Return the row count of this ResultSet. Only valid after processing is complete- Returns:
- the number of rows in this ResultSet
-
getColumnCount
public final int getColumnCount()Return the number of columns in this result set. Valid once we've seen the first row, so subclasses can use it during processing- Returns:
- the number of columns in this result set
-