-
Jan 18th, 2006, 04:20 AM
#1
count number of rows
Is it possible to do the sql-command "count * from table" with Spring? Can anyone provide some code to do this?
I know you can use the functions getRowCount and getColumnCount on the resultset. But this is only valid after processing is complete. I want to know the number of records before I proces. If the table is too large I don't want to proces the records...
-
Jan 18th, 2006, 04:47 AM
#2
In the meanwhile I already figured out a solution:
final ArrayList results = new ArrayList();
JdbcTemplate template =getJdbcTemplate();
class V_D_Table_Handler implements RowCallbackHandler{
public void processRow(ResultSet rs) throws SQLException{
Integer aantal = new Integer(rs.getInt(1));
results.add(aantal);
}
}
template.query("SELECT COUNT (*) FROM V_D_Table", new V_D_Table_Handler());
return results;
I'm sure there is a beter solution, because I return an ArrayList (which I always know the length is 1). But I can go further with this solution. any suggestions are still welcome.
-
Jan 18th, 2006, 08:36 AM
#3
This can be shortened to:
return getJdbcTemplate.queryForInt("SELECT COUNT (*) FROM V_D_Table");
Bill
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules