Saturday, August 18, 2007

counting rows in ResultSet

hey you,

if you find difficulty to count number of rows in ResultSet, hope my experience I write below helps.

The problem usually comes up because you try these lines of code:

rs.last();
int i = rs.getRow();
rs.first();

*rs = ResultSet

rs.first() trigger SQLException that caused by a database access error occurs OR the result set type is TYPE_FORWARD_ONLY

the easiest way I figured out is by changing the type of ResultSet like this:

Statement st = conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);


the 2 parameters of createStatement() method are resultSetType & resultSetConcurrency.
type of ResultSet are:
1. ResultSet.TYPE_FORWARD_ONLY
2. ResultSet.TYPE_SCROLL_INSENSITIVE
3. ResultSet.TYPE_SCROLL_SENSITIVE

type of Concurrency are:
1. ResultSet.CONCUR_READ_ONLY
2. ResultSet.CONCUR_UPDATABLE


That's all from now. Please indicate whether this information useful or not OR maybe you have better solution than this one. I am a leaner as well ^_^