|
Today in the WWW the XML is well established mechanism for data exchange. The webRowSet has all the functionality of the CachedRowSet as well as it is capable of reading and writing data directly from the xml file. The xml file which is used should have properties, metadata and actual data for the rowset object. The following example will illustrate the creation of xml data and how to use it in the RowSet object.
package com.visualbuilder;
import javax.sql.rowset.WebRowSet;
import com.sun.rowset.WebRowSetImpl;
public class WebRowSetExample { public static void main(String[] args) throws Exception{ Class.forName("org.postgresql.Driver"); WebRowSet webRs = new WebRowSetImpl(); webRs.setUsername("postgres"); webRs.setPassword("pass"); webRs.setUrl("jdbc:postgresql://localhost:5432/postgres"); webRs.setCommand("select * from dept"); webRs.execute(); java.io.FileWriter reader = new java.io.FileWriter("c:/dept.xml"); webRs.writeXml(reader); } }
Output:-
Note:- The example will create a file named dept.xml under the C Drive. The sample file dept.xml can be downloaded with the java source.
|