A WebRowSet (javax.sql.WebRowSet) object is a disconnected rowset that caches its data in memory in the same manner as a CachedRowSet object. A WebRowSet object is special because in addition to offering all the capabilities of a CachedRowSet object, it can write itself as an XML document and can also read that XML document to convert itself back to a WebRowSet object. Due to its XML support, WebRowSet is an ideal object format for web services. WebRowSet is also ideal for just painting a data for a single web page—a large-sized WebRowSet might introduce performance problems. Therefore, for better performance, you should keep its size as small as possible.
XML is the language through which disparate enterprises can communicate with each other, and has become the standard for web services communication. As a consequence, a WebRowSet object fills a real need by making it easy for web services to send and receive data from a database in the form of an XML document.
According to J2SE 5.0 documentation, WebRowSet describes the standard XML document format required when describing a RowSet object in XML and must be used by all standard implementations of the WebRowSet interface to ensure interoperability. In addition, the WebRowSet schema uses specific SQL/XML schema annotations, thus ensuring greater crossplatform interoperability. This is an effort currently under way at the ISO organization.
The schema definition describes the internal data of a RowSet object in three distinct areas:
The Creation and Population of WebRowSet
You can create a WebRowSet object and its associated metadata by using the following code fragments. Before creating a WebRowSet object, I set up a database table:mysql> use octopus; Database changed mysql> desc employees;
First, you need to create an empty WebRowSet object:
After creating an empty WebRowSet object, you can populate it:
Updating a WebRowSet Object
To update a WebRowSet object, you may update your desired rows(by using WebRowSet.
updateXXX()methods)and then invoke the WebRowSet.acceptChanges()method. The following
code fragment updates the first two rows in the WebRowSet object wrs:
Representing a WebRowSet Object as an XML Object
Writing a WebRowSet object to an XML document can be accomplished by using the WebRowSet.writeXml() method, which can take either an OutputStream object (if we want to write in bytes) or a Writer object (if we want to write in characters). This code snippet writes to a file called emps.xml using a FileWriter object:
The created emps.xml file will have three sections:
A generated XML document will contain a properties section, which will contain information about our connection, including the command associated with our WebRowSet object—SELECT id, name, age FROM employees—as well as other important information. The properties section of a WebRowSet object is depicted here (extracted from emps.xml):
The metadata section contains metadata about the structure of the columns that our WebRowSet object consists of. For each rowset’s column we have a <column-definition> element that describes the structure of the underlying column. The metadata section of a WebRowSet object is depicted here (extracted from emps.xml):The data section of a WebRowSet object is depicted here (extracted from emps.xml):
Here, I put all of the pieces together as a single program, which shows how to create a WebRowSet object and populate it from a database:
Running the Solution for a MySQL Database
Oracle Database Setup
Running the Solution for an Oracle Database
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.