Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC instantiate and load a new CachedRowSet object from a non-JDBC source
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Clark
instantiate and load a new CachedRowSet object from a non-JDBC source
1 Answer(s)      4 years ago
Posted in : JDBC


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


Advertisement
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
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
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
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... the data from a table then you can easily use the Hibernate Criteria load all
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
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
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
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
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
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
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
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 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
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
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
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
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
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
create a custom RowSetMetaData object from scratch
create a custom RowSetMetaData object from scratch  How can I create a custom RowSetMetaData object from scratch
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
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
Advertisements
 

 

 

DMCA.com