• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using CacheRowset

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The getDate returns a java.sql.Date. You can't cast that as a java.util.Date.
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greg,
I am confused.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pradeep Bhat:
Greg,
I am confused.


Me too.
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic