Java Reference
In-Depth Information
}
}
} catch (SQLException e) {
return false;
}
return false;
}
}
The filter is used by a FilteredRowSet to limit the visible results from a query.
As you will see, utilizing a FilteredRowSet provides the capability of filtering
data in an object-oriented manner at the applicaton level, rather than doing so at the
SQL database level. The benefit is that you can implement a series of filters and apply
them to the same result set, returning the desired result. Using such an option elimin-
ates the requirement to perform multiple database queries returning different data sets.
The following class demonstrates how to implement a FilteredRowSet . The
main () method calls a method that is appropriately named imple-
mentFilteredRowSet (), and it contains the code that is used to filter the results of
a query on the BOOK_AUTHOR and AUTHOR_WORK tables so that only results from
the authors with the last name of DEA and JUNEAU are returned:
package org.java8recipes.chapter13.recipe13_12;
import com.sun.rowset.FilteredRowSetImpl;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.RowSet;
import javax.sql.rowset.FilteredRowSet;
import
org.java8recipes.chapter13.recipe13_01.CreateConnection;
public class FilteredRowSetExample {
public static Connection conn = null;
public static CreateConnection createConn;
public static FilteredRowSet frs = null;
Search WWH ::




Custom Search