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:
Advertisements
nsstring load from filensstring
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
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 requestSession
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 tableHibernate 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 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
Open Source Application ServerOpen
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
Pass a dom object from jsp to servletPass 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 dstinationshortest 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 pathFileupload
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 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
Hibernate Load ExampleHibernate
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
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
objectobject 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
sourcesource 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
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 java code to create xml document from DOM objectjava 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