CachedRowSet (javax.sql.CachedRowSet) object is a disconnected (from the database) ResultSet object. CachedRowSet is a JavaBean, and this means that like any other JavaBean, implementations of javax.sql.CachedRowSet may be serialized. This allows for CachedRowSet objects to be serialized, sent to remote clients, updated, and then sent back to the server (including the database server). For example, a CachedRowSet object can be used as the data model for a Java servlet or JavaServer Pages (JSP) entry or edit form. The following is taken from the J2SE 5.0 documentation:
A CachedRowSet object is a container for rows of data that caches its rows in memory, which makes it possible to operate without always being connected to its data source. Further, it is a JavaBeans component and is scrollable, updatable, and serializable.
A CachedRowSet object typically contains rows from a result set, but it can also contain rows from any file with a tabular format, such as a spread sheet. The reference implementation (com.sun.rowset.CachedRowSetImpl class) supports getting data only from
a ResultSet object, but developers can extend the SyncProvider implementations to provide
access to other tabular data sources.
A CachedRowSet object can be used as the data model for a Java server-side entry or edit form. An application can modify the data in a CachedRowSet object, and those modifications can then be propagated back to the source of the data. According to J2SE 5.0 documentation, a CachedRowSet object is
. . . a disconnected rowset, which means that it makes use of a connection to its data source only briefly. It connects to its data source while it is reading data to populate itself with rows and again while it is propagating changes back to its underlying data source. The rest of the time, a CachedRowSet object is disconnected, including while its data is being modified. Being disconnected makes a RowSet object much leaner and therefore much easier to pass to another component. For example, a disconnected RowSet object can be serialized and passed over the wire to a thin client such as a personal digital assistant (PDA).
Therefore, a CachedRowSet object is special in that it can operate without being connected to its data source—that is, it is a disconnected RowSet object. It gets the name “CachedRowSet” from the fact that it stores (caches) its data in memory so that it can operate on its own data rather than on the data stored in a database.CachedRowSet is defined as
To create a CachedRowSet object, use its JavaBeans properties. The CachedRowSet properties allow it to connect to a database and retrieve data on its own. Table describes some of the properties necessary to initialize a CachedRowSet without a preexisting database connection.
The following code fragment illustrates creating a CachedRowSet object, setting its properties, and executing the command string in its command property:import java.sql.Connection; // database connection object
At this point, crs contains all of the selected data in the books table. After creating a CachedRowSet object, you may use ResultSet methods because the CachedRowSet object is effectively operating on a ResultSet object. We can navigate the rows in crs (by using the next() method), retrieve column values, update column values, insert new rows, and so on. For example, the next three lines of code go to the third row and retrieve the value in the first and second columns using ResultSet methods. You might be wondering whether this allows going back to any row, and the answer is yes. You also might be wondering what happens if any updates are done to this CachedRowSet object. If you do not commit changes to your database, then changes will not be reflected on the database at all.crs.absolute(3);
Once you create a CachedRowSet object, then you can extract its metadata by using this
CachedRowSetImpl Class Constructors
with the same default properties as the zero parameter constructor
You can make changes to a CachedRowSet object (i.e., its data) and then commit the changes back into the database. Therefore, for a given CachedRowSet object, you can not only read its data, but you can also propagate changes back to the database. For example, the following code segment updates a CachedRowSet object, and then commits changes back into its data source:crs.absolute(3);
To use a CachedRowSet object with JavaServer Pages (JSP), see the article “Get Disconnected with CachedRowSet.
The Oracle database imposes some constraints on CachedRowSet objects: all the constraints that apply to an updatable result set are applicable here except serialization, since OracleCachedRowSet is serializable. The SQL query has the following constraints:
In addition, a SQL query should also satisfy these conditions if inserts are to be performed:
JDBC Related Interview Questions
|Core Java Interview Questions||JSP Interview Questions|
|Java Servlets Interview Questions||EJB(Enterprise JavaBeans) Interview Questions|
|JSTL(JSP Standard Tag Library) Interview Questions||JNDI (Java Naming and Directory Interface) Interview Questions|
|Java Bean Utils Interview Questions||AWT (Abstract Window Toolkit) Interview Questions|
What Is Jdbc Programming?
Database Metadata, Part 1
Database Metadata, Part 2
Exploring Driver Property Information
Rowset Metadata A
Web Access To Metadata,part 1
Web Access To Metadata, Part 2
Rdf And Jdbc Metadata
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.