I want to retrieve some specific rows from ResultSet by using absolute(int row) method.I have retrieved all the rows in tabular format by following code:
public String[][] reference() {
String a[][]=new String[46][2];
int i=0;
try
{
con = getConnection();
stmt = con.createStatement(rs.TYPE_SCROLL_SENSITIVE,rs.CONCUR_READ_ONLY);
String sql="select logtime,beam_current from INDUS2_BDS.dbo.DCCT where logtime between '2014-10-10 07:17:00' and '2014-10-10 08:46:00'"+
"and (beam_current like '%9.96' or beam_current like '%9.97' or beam_current like '%9.98' or beam_current like '%9.99' or beam_current like '%0' or beam_current like '%_0.01' or beam_current like '%_0.02' or beam_current like '%_0.03' or beam_current like '%_0.04' or beam_current like '%_0.05' or beam_current like '%_0.06')";
stmt.executeQuery(sql);
rs = stmt.getResultSet();
while(rs.next())
{
for(int j=0; j<2; j++)
{
a[i][j] = rs.getString(j+1);
}
i++;
}
}
catch( Exception e )
{
System.out.println("\nException "+e);
}
finally
{
closeConnection(stmt, rs, con);
}
return a;
Now I only want to retrieve only 3,4,11,13,23,27,28 rows in-spite of all.How to do that?
Define int rowCounter=0;
before the while
and increase it in the end of the while
body.
Add a check if (rowCounter==3 || rowCounter==4 ...) { //do your logic}