home |contents |previous |next |seek  

 

 

 

 

 

     

 

2.3  CachedRowSet and FilteredeRowSet

o       The following line of code creates an empty object.

    CachedRowSet  rs = new CachedRowSetImpl();

     [ or  FilteredRowSet rs = new CachedRowSetImpl(); ]

    rs.setCommand("SELECT * FROM TITLES);

    rs.setURL("jdbc:myDriver:myAttribute");

    rs.setUsername("cervantes");

    rs.setPassword("sancho");

    rs.execute();

 

o       Using a CachedRowSet or FilteredeRowSet Object

      rs.setCommand("select * from COFFEES");

      rs.execute();

      rs.beforeFirst();

      while (rs.next()) {

String name = rs.getString("COF_NAME");

BigDecimal price = rs.getBigDecimal("PRICE");

System.out.println(name + " " + price);

}

 

o       Updating a CachedRowSet or FilteredeRowSet Object

      rs.absolute(3);

                                 rs.updateBigDecimal("PRICE", new BigDecimal("10.99"));

                                 rs.updateRow();

 

                                    or with Sql

                                                rs.setCommand ("UPDATE  .... SET....

                                                rs.execute();

 

 

o       Inserting a Row

rs.moveToInsertRow();

rs.updateString("COF_NAME", "House_Blend");

rs.updateInt("SUP_ID", 49);

rs.updateBigDecimal("PRICE", new BigDecimal("7.99"));

rs.updateInt("SALES", 0);

rs.updateInt("TOTAL", 0);

rs.insertRow();

rs.moveToCurrentRow();

 

or with Sql

                                                rs.setCommand ("INSERT INTO....

                                                rs.execute();

 

o       Deleting a Row

rs.last();

rs.deleteRow();

 

or with Sql

                                                rs.setCommand ("DELETE FROM....

                                                rs.execute();

A FilteredRowSet object, an extension of a CachedRowSet object, lets a programmer use a filtered subset of data from a rowset. For example, suppose a FilteredRowSet object contains a fairly large set of rows. A programmer who wants to perform operations on only a subset of those rows can specify a range of values, and the FilteredRowSet object will return only values in that range.

 

 

public class Filter implements Predicate {

   ……………

}

 

        Filter  fil= new Filter();

        rs.setFilter(fil);

 

 

 

Copyright©2008. All rights reserved.