This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

ClassCaseException

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a MS SQL Server DB I am reading data from and populating a bean.
I hace a DATETIME Field in the DB and I get a Classcast Exception when I try to read it off my ResultSet. If anybody can share the code of how to get around this, it would be very helpful.

(I never got this problem in Oracle's DATE datatype - rs.getDate(COLUMN_NAME))
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't post the same question to multiple forums -- it just wastes people's time. Also, please use the appropriate forum for your questions: as this is a JDBC question, that's where I'll move it for you. I've already deleted the duplicates.
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would prefer to see your code where you are facing problem.

Shailesh
 
b rag
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
resultSet.getDate("VACC_EXP_DATE")

I have tried many combinations. I would like to know how to fetch a DATETIME value in the SQLSERVER DB to my JSP (I dont intend changing it to TIMESTAMP).

Thanks
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
since you are getting a ClassCastException only a syntax would not suffice.
you need to provide atleast complete line.

when you are invoking resultSet.getDate("VACC_EXP_DATE") what is then variable type you are assigning it .

also provide StackTrace of exception

thanks
[ April 08, 2005: Message edited by: Shailesh Chandra ]
 
b rag
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is how the messages start.

java.lang.ClassCastException: java.sql.Timestamp
at resultSet.getDate(resultSet.java:233)

As I said, the Datatype is DATETIME and it is on MS SQL Server.

Thanks.
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you will have to map it to timestamp, because datetime field will represent date and time both but as per java doc java.sql.Date is meant to represent date only.

From the javadoc


To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated.




visit this link . This document tell that datetime is mapped to timestamp in sql server.
[ April 08, 2005: Message edited by: Shailesh Chandra ]
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic