Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CachedRowSetImpl.getTimestamp() throwing exception

43 views
Skip to first unread message

itref...@gmail.com

unread,
Nov 13, 2006, 2:58:37 PM11/13/06
to
Hello,
If anyone has faced this problem or can guide me in right direction
please..
I am clueless abt this exception. I have a java piece of code as (note:
implementation of CachedRowSetImpl comes default with JRE1.5 in
com.sun.rowset.CachedRowSetImpl):


ResultSet rs = stmt.executeQuery(sql);

CachedRowSetImpl crs = new CachedRowSetImpl();
crs.populate(rs);

while (crs.next()) {
java.sql.TimeStamp = crs.getTimestamp("EOD_DATE"); // EOD_DATE coulmn
is of type DATE, this line is throwing exception, why???
}

when result set contains a column of DATE (in Oracle 9.2.0.4 version,
inserted using SYSDATE), program is throwing this exception:

java.lang.ClassCastException: java.sql.Timestamp
at
com.sun.rowset.CachedRowSetImpl.getTimestamp(CachedRowSetImpl.java:2289)
at
com.sun.rowset.CachedRowSetImpl.getTimestamp(CachedRowSetImpl.java:2740)
at
com.itaas.action.chart.DailyTunerActivityChart.createDataset4(DailyTunerActivityChart.java:190)
at
com.itaas.action.chart.DailyTunerActivityChart.getChartObject(DailyTunerActivityChart.java:68)
at
com.itaas.action.DailyTunerAction.execute(DailyTunerAction.java:104)
at
org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:53)
at
org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:64)
at
org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:48)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at
org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:280)
at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1858)
... and so on

joe.we...@gmail.com

unread,
Nov 13, 2006, 3:06:02 PM11/13/06
to


Hi. I bet this is due to a bug in later Oracle drivers. Try this
added property to add to your connections:

props.put("oracle.jdbc.V8Compatible", "true");

Let me know if this clears the problem up...
Joe Weinstein at BEA Systems

itref...@gmail.com

unread,
Nov 13, 2006, 3:42:09 PM11/13/06
to
joeN...@BEA.com wrote:
> Hi. I bet this is due to a bug in later Oracle drivers. Try this
> added property to add to your connections:
>
> props.put("oracle.jdbc.V8Compatible", "true");
>
> Let me know if this clears the problem up...
> Joe Weinstein at BEA Systems

Thank u sir! :)
This worked like magic.I am all praise for u.

bjor...@gmail.com

unread,
Dec 4, 2006, 4:46:30 PM12/4/06
to
I Tested that with oracle Jdbc version 10.2.0.1 and gott it to work. :D

My Test code
import java.sql.Timestamp;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.sun.rowset.CachedRowSetImpl;
import java.sql.Date;


public class CachedRowSetImplTest {

public static void main(String args []) {
CachedRowSetImplTest runMe = new CachedRowSetImplTest();
}
/** Creates a new instance of CachedRowSetImplTest */
public CachedRowSetImplTest() {

Connection conn;
try {

DriverManager.registerDriver(new
oracle.jdbc.driver.OracleDriver());
} catch (SQLException ex) {
ex.printStackTrace();
}
try {
conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ora10gr2",
"scott", "tiger");
} catch( Exception e ) {
System.out.println( "error connecting" );
e.printStackTrace( );
return;
}
try {
// Create a Statement
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select ename, hiredate
from emp");


CachedRowSetImpl crs = new CachedRowSetImpl();

crs.populate(rset);
System.out.print("test");
while (crs.next()) {
//java.sql.TimeStamp =
Timestamp myTimeStamp = crs.getTimestamp("HIREDATE");


// EOD_DATE coulmn is of type DATE, this line is throwing

System.out.println(crs.getTimestamp("HIREDATE"));

}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
itref...@gmail.com skrev:

itref...@gmail.com

unread,
Dec 17, 2006, 8:52:30 PM12/17/06
to
Thanx for sharing code. Yeah, i think oracle guys fixed that bug in new
driver version. However there is an alernate solution to the problem if
u r still using 9.2* version of drivers i.e oracle does its own
implementation CachedRowSet (look for OracleCachedRowSet in oro*.jar
file shipped with installation, sorry can't remember exact jar file
name) and that takes care of TimeStamp related issue.I was using Sun
implementation of CachedRowSet with Oracle db, hence faced that
exception.
0 new messages