• 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

ClassCaseException

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Do you pee on your compost? Does this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic