Using FilteredRowSet to filter Jobs

Last Modified On : 2-july-2008

import java.sql.*; 
import javax.sql.*;
import oracle.jdbc.rowset.*;

public class FilteredRowSetDemo {
    
    public static void main(String[] args) throws Exception{
        OracleFilteredRowSet rs = new OracleFilteredRowSet();
        rs.setUrl("jdbc:oracle:thin:@localhost:1521:XE");
        rs.setUsername("hr");
        rs.setPassword("hr");
        rs.setCommand("select * from jobs");
        rs.setFilter( new PredicateImpl());
        rs.execute();
        while ( rs.next() ) {
              System.out.println( rs.getString("job_title") + ":" + rs.getString("min_salary"));
        }
        rs.close();
         
    }
}

class  PredicateImpl implements OraclePredicate
{
    public boolean evaluate(RowSet rs) {
        try {
          int minsal = rs.getInt(3);
          if ( minsal > 5000)
            return true;
          else
              return false;
        }
        catch(Exception ex) {
           return false;
       }
    }
    public boolean evaluate(Object object, int i) throws SQLException {
        return true;
    }

    public boolean evaluate(Object object, String string) throws SQLException {
        return true;
    }
}