wood burning stoves 2.0*
The moose likes JDBC and the fly likes ClassCaseException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ClassCaseException" Watch "ClassCaseException" New topic
Author

ClassCaseException

b rag
Greenhorn

Joined: Mar 31, 2005
Posts: 6
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))
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

I would prefer to see your code where you are facing problem.

Shailesh


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
b rag
Greenhorn

Joined: Mar 31, 2005
Posts: 6
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

Joined: Aug 13, 2004
Posts: 1081

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

Joined: Mar 31, 2005
Posts: 6
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

Joined: Aug 13, 2004
Posts: 1081

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassCaseException