Java Reference
In-Depth Information
is passed to the filter rather than a position, and the second evaluate() method is
called if a column position is passed. The final evaluate() method accepts the
RowSet itself, and it does the work of going through the data and returning a
Boolean to indicate whether the corresponding column name/position values match
the filter data.
The second part of the FilteredRowSet implementation is the work of the
FilteredRowSet . This can be seen within the implementFilteredRowSet()
method of the FilteredRowSetExample class. The FilteredRowSet will ac-
tually use the filter class that you've written to determine which rows to display. You
can see that the array of values that will be passed to the filter class is the first declara-
tion within the method. The second declaration is the instantiation of the filter class
AuthorFilter . Of course, the array of filter values and the column position that
corresponds to the filter values is passed into the filter constructor.
String[] authorArray = {"DEA", "JUNEAU"};
// Creates a filter using the array of authors
AuthorFilter authorFilter = new AuthorFilter(authorArray,
2);
To instantiate a FilteredRowSet , create a new instance of the
FilteredRowSetImpl class. After it is instantiated, simply set the SQL query that
will be used to obtain the results using the setCommand() method and then execute
it by calling the executeQuery() method.
// Instantiate a new FilteredRowSet
frs = new FilteredRowSetImpl();
// Set the query
frs.setCommand("SELECT TITLE, LASTNAME "
+ "FROM BOOK_AUTHOR BA, "
+ "AUTHOR_WORK AW, "
+ "BOOK B "
+ "WHERE AW.AUTHOR_ID = BA.ID "
+ "AND B.ID = AW.BOOK_ID");
// Execute the query
frs.execute(conn);
Search WWH ::




Custom Search