Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using CacheRowset

 
Sahil Sharma
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using CachedRowSet(sun.jdbc.rowset.CachedRowSet) getDate("DATE") function. Result from this method i am storing in util date. But while storing i ma getting class cast exception. I have looked at the database the column is also of date type. I am using Weblogic 8.1 and Oracle 9i.
Any Suggestions.
Thanx
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The getDate returns a java.sql.Date. You can't cast that as a java.util.Date.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Thomas Paul:
The getDate returns a java.sql.Date. You can't cast that as a java.util.Date.

java.util.Date is a superclass of java.sql.Date. So casting a subclass to superclass should not be a problem.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it will be a problem. java.sql.Date is just that. Date. No time. java.util.Date is actually a DateTime class.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg,
I am confused.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pradeep Bhat:
Greg,
I am confused.

Me too.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I must confess I'm confused as well.
Casting a java.sql.Date to java.util.Date is fine. The other way around, of course, won't work. And while a java.sql.Date object is not supposed to have a time portion, that isn't actually being enforced.
It's not clear to me what's happening. Sahil, the ClassCastException will tell you (a) what the actual class of the object is that you were trying to cast, and (b) what the line number of the cast is, so you can see in the source what class you were trying to cast the object to. These two ingredients should tell you most of what you need to know, and if any questions remain then they would really help us help you.
- Peter
[ October 15, 2003: Message edited by: Peter den Haan ]
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think we need to see the actual instruction that is causing the problem and the actual error message in order to help further.
 
Sadaf Ahmed
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am facing the same problem. The getDate() function in this case is returnign a java.sql.Timestamp object due to which it is throwing a ClassCastException.

I tried the following code -
java.sql.ResultSet rs = statement.executeQuer("select * from table");
while(rs.hasNext()) {
java.sql.Date dt = rs.getDate("dateColumn");
System.out.println("Date --> " + dt);
}
This worked fine. But the moment I shifted to CachedRowSet it gave error for the same column -
java.sql.ResultSet rs = statement.executeQuer("select * from table");
CachedRowSet rowset = new CachedRowSetImpl();
rs = rowset.populate(rs);
while(rs.hasNext()) {
java.sql.Date dt = rs.getDate("dateColumn"); //ClassCastException here
System.out.println("Date --> " + dt);
}

Could anybody please help!!!

Regards,
Sadaf
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sadaf,

1) What is datatype dateColumn in database
2) Your problem is related to resultset not rowset as you are invoking rs.getDate("dateColumn"); and rs is ResultSet, even you are not using rowset except you are populating it.
3) Please verify that your dateColumn is of Date type and it is not timestamp


one more thing that original post is more than one year old it is better to start new thread.


Shailesh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic