instantiate and load a new CachedRowSet object from a non-JDBC source

instantiate and load a new CachedRowSet object from a non-JDBC source

How can I instantiate and load a new CachedRowSet object from a non-JDBC source?

View Answers

November 15, 2010 at 11:29 AM

Hi friends,

The basics are: * Create an object that implements javax.sql.RowSetReader, which loads the data. * Instantiate a CachedRowset object. * Set the CachedRowset's reader to the reader object previously created. * Invoke CachedRowset.execute().

Note that a RowSetMetaData object must be created, set up with a description of the data, and attached to the CachedRowset before loading the actual data. The following code works with the Early Access JDBC RowSet download available from the Java Developer Connection and is an expansion of one of the examples: // Independent data source CachedRowSet Example import java.sql.*; import javax.sql.*; import sun.jdbc.rowset.*;

public class RowSetEx1 implements RowSetReader { CachedRowSet crs; int iCol2; RowSetMetaDataImpl rsmdi; String sCol1, sCol3;

public RowSetEx1() { try { crs = new CachedRowSet(); crs.setReader(this); crs.execute(); // load from reader

System.out.println( "Fetching from RowSet..."); while(crs.next()) { showTheData(); } // end while next

if(crs.isAfterLast() == true) { System.out.println( "We have reached the end"); System.out.println("crs row: " + crs.getRow()); }

System.out.println( "And now backwards...");

while(crs.previous()) { showTheData(); } // end while previous

if(crs.isBeforeFirst() == true) { System.out.println( "We have reached the start"); }

crs.first(); if(crs.isFirst() == true) { System.out.println( "We have moved to first"); }

System.out.println("crs row: " + crs.getRow());

if(crs.isBeforeFirst() == false) { System.out.println( "We aren't before the first row."); }

crs.last(); if(crs.isLast() == true) { System.out.println( "...and now we have moved to the last"); }

System.out.println("crs row: " + crs.getRow());

if(crs.isAfterLast() == false) { System.out.println( "we aren't after the last."); }

} // end try catch (SQLException ex) { System.err.println("SQLException: " + ex.getMessage()); }

} // end constructor

public void showTheData() throws SQLException { sCol1 = crs.getString(1); if(crs.wasNull() == false) { System.out.println("sCol1: " + sCol1); } else { System.out.println("sCol1 is null"); }

iCol2 = crs.getInt(2); if (crs.wasNull() == false) { System.out.println("iCol2: " + iCol2); } else { System.out.println("iCol2 is null"); }

sCol3 = crs.getString(3); if (crs.wasNull() == false) { System.out.println("sCol3: " + sCol3 + "\n" ); } else { System.out.println("sCol3 is null\n"); }

} // end showTheData

// RowSetReader implementation public void readData(RowSetInternal caller) throws SQLException { rsmdi = new RowSetMetaDataImpl(); rsmdi.setColumnCount(3); rsmdi.setColumnType(1, Types.VARCHAR); rsmdi.setColumnType(2, Types.INTEGER); rsmdi.setColumnType(3, Types.VARCHAR); crs.setMetaData( rsmdi );

crs.moveToInsertRow();

crs.updateString( 1, "StringCol11" ); crs.updateInt( 2, 1 ); crs.updateString( 3, "StringCol31" ); crs.insertRow();

crs.updateString( 1, "StringCol12" ); crs.updateInt( 2, 2 ); crs.updateString( 3, "StringCol32" ); crs.insertRow();

crs.moveToCurrentRow(); crs.beforeFirst();

} // end readData

public static void main(String args[]) { new RowSetEx1(); }

} // end class RowSetEx1

Thanks.









Related Tutorials/Questions & Answers:
instantiate and load a new CachedRowSet object from a non-JDBC source
instantiate and load a new CachedRowSet object from a non-JDBC source  How can I instantiate and load a new CachedRowSet object from a non-JDBC source
custom RowSetReader get called from a CachedRowSet.
custom RowSetReader get called from a CachedRowSet.  How does a custom RowSetReader get called from a CachedRowSet
Advertisements
nsstring load from file
nsstring load from file  Hi, How to load file data into NSString object? Example of nsstring load from file, basically the html file data into NSSTring object. Thanks
Load UIImage from URL
Load UIImage from URL  Load UIImage from URL
create a new object in JavaScript
create a new object in JavaScript  How do you create a new object in JavaScript
create a new object in JavaScript
create a new object in JavaScript  How do you create a new object in JavaScript
Download and Build from Source
Download and Build from Source Shopping cart application developed using Struts 2.2.1 and MySQL can be downloaded from... Shopping Cart Features Database Design Creating Data Access Object
Session Object from request
Session Object from request  Why are we getting session object from... getting cookie object from request object? I know all methods are available its relevant class. is there any reason for getting session object from request
How to load file from the directory in J2ME?
How to load file from the directory in J2ME?  Video player J2ME. I have a folder name "music". I want to display all file with extension is "*.mpg" on the List. How can I do it, plz help me
Hibernate Criteria load all objects from table
Hibernate Criteria load all objects from table - Learn how to load all the data from a table (not good choice if large amount of data is present in table... from a table then you can easily use the Hibernate Criteria load all objects
how to load a table of data from oracle, to a jsp page using hashmap.
how to load a table of data from oracle, to a jsp page using hashmap. ... to this data i have to retrieve their details from the database(oracle). I have to use the hashmap.How can i convert a result set object to hashmap object
new operator for creating the object of inner class
new operator for creating the object of inner class  Hi , The folliowing is my code : class Outer { class Inner{ void show...[]) { Outer objOuter = new Outer(); Outer.Inner objInner = objOuter.new Inner
Select from drop down and load the appropriate application resource.properties in struts2
Select from drop down and load the appropriate application resource.properties in struts2  I would like to use a dropdown for selecting a language in my application .On selecting a language the appropriate
Load Coursenames from MS Acess Database to JComboBox - Java Beginners
Load Coursenames from MS Acess Database to JComboBox  Hello sir, I want to Load/add Course names which stored in Ms Acess 2007 Database, plz help... sf=new SwingFrame(); } public SwingFrame(){ JFrame f = new JFrame("Frame
How to load elements from db when i press next.
How to load elements from db when i press next.  Hello , I am working on a project "Online Book Mart" using JSP and Servlets and I am astuck... means when i click next, the next 20 books will be displayed from db on the same
create a custom RowSetMetaData object from scratch
create a custom RowSetMetaData object from scratch  How can I create a custom RowSetMetaData object from scratch
Open Source Application Server
Open Source Application Server New Open-Source Application Server A new open source application server is available for download from WSO2 Inc...;  WS02 Debuts Tungsten, Open Source Application Server WSO2, a new start-up
I retrieve a String or other object type without creating a new object each time.
I retrieve a String or other object type without creating a new object each time.  How can I retrieve a String or other object type without creating a new object each time
Pass a dom object from jsp to servlet
Pass a dom object from jsp to servlet  I am creating a dom object in my jsp page. now i want to pass that object in a servlet through calling servlet in jsp. can anyone help me
shortest path from the given source to dstination
shortest path from the given source to dstination  Hi. Here in my databse. CREATE TABLE b ( id int(10) unsigned NOT NULL AUTO_INCREMENT, source... to find the shortest path from the given source to destination based
Fileupload from source path to destination path
Fileupload from source path to destination path  first we will create... source path &Destination path fields and BOTH INPUT TYPES ARE "TEXT" we will give source path as statically where the .doc or .rtf files path will be their.and
how to load value in dropdown list after selecting value from first dropdown list using javascript
how to load value in dropdown list after selecting value from first dropdown list using javascript  how to load value in dropdown list after selecting value from first dropdown list using javascript
How can i add a new count to this source code ? - Java Beginners
How can i add a new count to this source code ?  Hi everyone I...(String[] args) throws IOException { Test test = new Test...; TreeMap> xtsmMap = new TreeMap>(); try
How can i add a new count to this source code ? - Java Beginners
How can i add a new count to this source code ?  Hi everyone I...) throws IOException { Test test = new Test(); test.execute...; TreeMap> xtsmMap = new TreeMap>(); try
how to focus on the new window opened from JSF ?
how to focus on the new window opened from JSF ?  Hi guys, I have commandLink with action which using javascript to open a new window(window.open()). Problem is, the new window opens at background behind the current window
Photoshop Tutorial : How to remove an object from a picture
How to remove an object from a picture       We are going to learn the method to remove an object from a picture. If you want to remove an object, which you don't want to like
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access  import javax.swing.*; import java.awt....("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:trrl
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access  import javax.swing.*; import java.awt....("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:trrl
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access  import javax.swing.*; import java.awt....("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:trrl
Which splunk component is used for getting data from data source
for getting data from a data source. Which splunk component is used for getting data from data source? Thanks   Hi, You can configure the datasource...Which splunk component is used for getting data from data source  Hi
Hibernate Load Example
Hibernate Load Example - Learn how to use the session.load() method... the session.load() method to load an entity by its primary key. Here is the most used method for loading the entity: load(Class theClass, Serializable id
How to get jSon object in servlet from jsp - JSP-Servlet
How to get jSon object in servlet from jsp  How to get jSon object in servlet from jsp? In jsp page i have written: var sel...'; httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); httpRequest.open("POST", url, true
Can you instantiate the Math class? - Java Beginners
Can you instantiate the Math class?   Hi, Can you create object of Math class? Thanks   Hi, All the methods in Math class... the object of Math class. Thanks
XML load problem - XML
function load(){ var loadXML = new ActiveXObject...XML load problem  I have load the xml document in javascript.getting..., Plz give full details with source code to solve the problem and visit
UIWebview load url
://www.roseindia.net"]; // Load URL //Create a URL object. NSURL *url = [NSURL...UIWebview load url  How to load website url in UIWebview? Tell me code for UIWebview load url of a website Thanks
object
object  is it possible to create object in the same class..?.  ...(){ System.out.println("I have an object."); } public static void main(String[] args) { CreateObject obj=new CreateObject
org.hibernate.MappingException: could not instantiate id generator
org.hibernate.MappingException: could not instantiate id generator  I am getting the following exception while running Hibernate example, pls..." org.hibernate.MappingException: could not instantiate id generator
org.hibernate.MappingException: could not instantiate id generator
org.hibernate.MappingException: could not instantiate id generator  I am getting the following exception while running Hibernate example, pls..." org.hibernate.MappingException: could not instantiate id generator
org.hibernate.MappingException: could not instantiate id generator
org.hibernate.MappingException: could not instantiate id generator  I am getting the following exception while running Hibernate example, pls..." org.hibernate.MappingException: could not instantiate id generator
org.hibernate.MappingException: could not instantiate id generator
org.hibernate.MappingException: could not instantiate id generator  I am getting the following exception while running Hibernate example, pls..." org.hibernate.MappingException: could not instantiate id generator
source
source  how to pass the morethan one fields from one page to another page in struts1.2? i am using tchnologies are struts1.2 oracle 10g myecllipse 8.6 so please post the exact source code to support the above technologies
Loading properties from a XML file
Loading properties from a XML file       This Example shows you how to Load properties from a XML... we can save properties to a stream and also load properties from a stream.ADS
Java - Opening a url in new window from an applet
Java - Opening a url in new window from an applet       This is the example of opening a url from an applet. This program shows that how a url is opened in a new document or browser
PHP Create Instance
need to access the variables of a class from an object we use -> operator sign. To instantiate an object we need to use new operator as:ADS_TO_REPLACE_1...Create an Instance: In OOPs programming we need to instantiate each object
For every option selected from a dropdown a new textbox opens
For every option selected from a dropdown a new textbox opens  I have a dropdown with four options, each time I select an option a new text box should open below. please guide.In urgent need.   The given code displays
Access properties of bean from request object using OGNL.
Access properties of bean from request object using OGNL. In this section, we will introduce you how to access beans properties from request object using...; }ADS_TO_REPLACE_23 StudentDetails bean = new
Can we instantiate abstract class in Java?
Can we instantiate abstract class in Java?  HI, Can we instantiate abstract class in Java? Thanks   Hi, No, you can't instantiate an abstract class. Thanks
java code to create xml document from DOM object
java code to create xml document from DOM object  Hey! After knowing the way we can create DOM objects and add elements to it-> then displaying it on the console ;is there a way I can output the same in xml document
new
new    hi i am jane pls explain the difference between string greeting = good morning string greeting = new string ("good morning
new
new    hi i am jane pls explain the difference between heap memory and stack memory

Ads