Manufacturing a Disconnected CachedRowset
From: Shuaib Kauchali (kauchalis_at_nospamiola.com)
Date: 03/29/04
- Next message: Antonio: "Re: OC4j and abnormal exit of stm.executeQuery"
- Previous message: te: "FileMaker Pro 7, IBM DB2, - new !"
- Next in thread: Abdullah Kauchali: "Re: Manufacturing a Disconnected CachedRowset"
- Reply: Abdullah Kauchali: "Re: Manufacturing a Disconnected CachedRowset"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 29 Mar 2004 11:44:08 +0200
Hi folks,
Just downloaded Sun's Early Access implementation of JDBC CachedRowset
(Rowset) [3]. I am trying to create (manufacture) a CachedRowset without
any direct links to a backend database. These are my steps:
i. Create a RowsetMetaData object (which defines the fields/columns etc);
ii. Instantiate a CachedRowset and set the metadata property to i. above;
iii. Set some CachedRowset properties that will allow for updating;
iv. Populate the CachedRowset
I have succeeded (or it seems) with the above, but I fail to scroll thru the
populated CachedRowset (to get the data out). The error I get is:
java.sql.SQLException: Invalid Cursor position
at com.sun.rowset.CachedRowSetImpl.next(CachedRowSetImpl.java:1201)
at
com.capitalalliance.integration.universe.common.TestCachedRowset.main(TestCa
chedRowset.java:51)
The execution fails on crs.next().
What am I missing, any ideas?
Many thanks in advance,
Regards
S Kauchali
References:
[1]
http://java.sun.com/developer/technicalArticles/javaserverpages/cachedrowset/
[2] http://java.sun.com/developer/Books/JDBCTutorial/chapter5.html
Download:
[3] http://java.sun.com/developer/earlyAccess/jdbc/jdbc-rowset.html
Platform details:
JDK 1.4.2_04
Windows XP Pro
////////////////////code///////////////////
/*
* Created on Mar 29, 2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.capitalalliance.integration.universe.common;
/**
* @author Shuaib Kauchali
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
import javax.sql.rowset.*;
import javax.sql.*;
import com.sun.rowset.*;
import java.sql.*;
public class TestCachedRowset {
public static void main(String[] args) {
try {
RowSetMetaData rowMeta = new RowSetMetaDataImpl();
rowMeta.setColumnCount(49);
for (int i = 1; i < 50; i++) {
rowMeta.setColumnName(i, "columnno" + String.valueOf(i));
rowMeta.setColumnType(i, 12);
i++;
}
CachedRowSet crs = new CachedRowSetImpl();
crs.setFetchDirection(ResultSet.FETCH_FORWARD);
crs.setType(ResultSet.TYPE_SCROLL_INSENSITIVE);
crs.setConcurrency(ResultSet.CONCUR_UPDATABLE);
crs.setTableName("MyTable");
crs.setMetaData(rowMeta);
int j=1;
for (int k = 1; k < 10; k++) {
crs.moveToInsertRow();
for (j = 1; j < 50; j++) {
crs.updateString(j, "value isss =" + j + k);
}
crs.insertRow();
}
while (crs.next()) { //<-- bombs out here
System.out.println(crs.getString(1));
System.out.println(crs.getString(2));
System.out.println(crs.getString(3));
System.out.println(crs.getString(4));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
- Next message: Antonio: "Re: OC4j and abnormal exit of stm.executeQuery"
- Previous message: te: "FileMaker Pro 7, IBM DB2, - new !"
- Next in thread: Abdullah Kauchali: "Re: Manufacturing a Disconnected CachedRowset"
- Reply: Abdullah Kauchali: "Re: Manufacturing a Disconnected CachedRowset"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]