Thursday, October 18, 2018

Using FilteredRowSet to filter Jobs

 


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;
    }
}

No comments:

Post a Comment

CORBA Java Tutorial using Netbeans and Java 8.

CORBA-Example A simple CORBA implementation using Java Echo.idl module EchoApp{ interface Echo{ string echoString(); }; }; ...