advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the code for this article
Partners & Affiliates
advertisement
advertisement
advertisement
Average Rating: 3.5/5 | Rate this item | 2 users have rated this item.
Email this articleEmail this article
 
Master the FilteredRowSet Interface for Disconnected Data Retrieval
The FilteredRowSet interface, added to version 1.5 of Java, lets you retrieve a custom view of database data using a filter that takes a snapshot, but doesn't alter, your table. Best of all, it does this without a persistent database connection.  

advertisement
he latest version of Java, J2SE 5.0 (version 1.5 of the JDK) is the first to deliver the concept of disconnected RowSet objects to the Java language. The FilteredRowset interface extends from the WebRowSet interface, which in turn extends from the javax.sql.Rowset interface. As you will see, the FilteredRowSet lets one narrow down the number of rows in a disconnected object based on filtering logic you provide without requiring an ongoing connection to your database. In this article, I'll introduce you to FilteredRowSet objects.


Where Oh WHERE Clause?
If you were using simple JDBC, you could achieve the same thing using a WHERE clause in a query using a JdbcRowset object. But JdbcRowset objects require a connection to the database, whereas RowSet objects (a superset of FilteredRowSet objects) do not (i.e., they are disconnected). A WHERE clause requires a connection to the database to filter your database data. With the FilteredRowSet, you can retrieve your data from the database and then disconnect. As you will see, the FilteredRowSet uses Predicate objects to retrieve data from RowSet objects without a database connection using WHERE-like logic.

A Real World Example
I've decided to build a fun example to help facilitate understanding. This application will retrieve NBA (National Basketball Association) player statistics for the 2003-04 season. Don't worry, you don't need to know much about basketball for this study. You'll build a database table that stores player data including games played (G), field goals made (FG), free throws made (FT), total points scored (P), and average points per game (PG).

To do this, you'll need a database and, of course, a database table. You can choose any database you prefer but it must support FilteredRowSet objects, which are an offering of Java 1.5. I am going to use IBM's DB2 8.1, which you can download as a trial from http://www-306.ibm.com/software/data/db2/udb/v8/.

I'll start by creating a database using the DB2 command line processor:


db2 => create database balldb
Next, I'll connect to the database with my user name (db2admin) and password (db2admin).

db2=> connect to balldb user db2admin using db2admin
Next, I'll create a table (named STATS) to house all the statistical data mentioned above. The following statement creates the table:

db2=> create table stats (firstname varchar(40) not null, lastname varchar(40) 
   not null, team varchar(40) not null, G int not null, FG int not null, FT int not null, P int not null,
PG decimal(3,1) not null)
I need some data in my table. In the real world, this table would likely have data for all the players in the NBA. For the purposes of this example, I've included only 10 players in the table—namely the players with the highest average points per game during the 2003-2004 regular season:

Table 1. The NBA Table Data.
FIRSTNAME LAST NAME TEAM G FG FT P PG
Tracy McGrady Orlando Magic 67 653 398 1,878 28.0
Predrag Stojakovic Sacremento Kings 81 665 394 1,964 24.2
Kevin Garnett Minnesota Timberwolves 82 804 368 1,987 24.2
Kobe Bryant Los Angeles Lakers 65 516 454 1,557 24.0
Paul Pierce Boston Celtics 80 602 517 1,836 23.0
Baron Davis New Orleans Hornets 67 554 237 1,532 22.9
Vince Carter Toronto Raptors 73 608 336 1,645 22.5
Tim Duncan San Antonio Spurs 69 592 352 1,538 22.3
Dirk Nowitzki Dallas Mavericks 77 605 371 1,680 21.8
Michael Redd Milwaukee Bucks 82 633 383 1,776 21.7

The following statement inserts the first row into the database.


insert into stats values ('Tracy','McGrady','Orlando Magic',67,653,398,1878,28.0)
You can add each of the remaining nine rows with appropriate data using the same process, until the table is complete.

  Next Page: The Predicate Interface


Page 1: IntroductionPage 3: Applying the Filter
Page 2: The Predicate Interface 
Untitled
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Intel PDF: Virtualization Delivers Data Center Efficiency
Intel eBook: Managing the Evolving Data Center
Microsoft Article: BitLocker Brings Encryption to Windows Server 2008
Symantec eBook: The Guide to E-Mail Archiving and Management
Microsoft Article: RODCs Transform Branch Office Security
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
Avaya Article: Advancing the State of the Art in Customer Service
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Avaya Article: Avaya AE Services Provide Rapid Telephony Integration with Facebook
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Seminar: Efficiencies in Hardware/Software Virtualization
HP Webcast: Disaster Recovery Planning
Go Parallel Video: Performance and Threading Tools for Game Developers
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
IBM TCO eKIT: Your IT Budget is Under Attack, Get in Control
IBM Energy Efficiency eKIT: Learn How to Reduce Costs
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Microsoft Article: Silverlight Streaming--Free Video Hosting for All
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
HP Demo: StorageWorks EVA4400
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES