In this tutorial, we introduce the JDBC RowSet interface and its subinterfaces JdbcRowSet and CachedRowSet that support connected and disconnected database access, respectively. You will learn to connect to a database via class JdbcRowSetImpl--the reference implementation of the JdbcRowSet interface that Sun provides with JDK 5.0. You will also learn to use the JdbcRowSetImpl object to execute a SQL query and obtain its results. This tutorial is intended for students and professionals who are already familiar with Java and basic JDBC capabilities.
To execute the example in this tutorial, you must install JDK 5.0, MySQL and the MySQL Connector/J, then create our books database. A script to help create the database is located in the example download for this article. If you would like to execute this example on your own computer, we provide instructions for setting up MySQL and creating the database.
[Notes: This is an excerpt (Section 25.10) of Chapter 25, Accessing Databases with JDBC, from our best-selling textbook Java How to Program, 6/e. This tutorial may refer to other chapters or sections of the book that are not included here. When you purchase this book you also get free access to the Web-based Java Multimedia Cyber Classroom, 6/e, for six months. The Cyber Classroom includes audio descriptions of the examples in Chapters 1-14, solutions to approximately one-half of the end-of-chapter exercises, interactive true/false self-assessment questions and a searchable Web-based e-book. Permission Information: Deitel, Harvey M. and Paul J., JAVA HOW TO PROGRAM, ©2005, pp. 1224-1227. Electronically reproduced by permission of Pearson Education, Inc., Upper Saddle River, New Jersey.]
Java RowSet Tutorial: Using the RowSet Interface (Continued)
Figure 25.32 reimplements the example of Fig. 25.25 using a RowSet. Rather than establish the connection and create a Statement explicitly, Fig. 25.32 uses a JdbcRowSet object to create a Connection and a Statement automatically.
|
|||
| Fig. 25.32 | Displaying the authors table using JdbcRowSets. | ||

