File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ClassCaseException

 
b rag
Greenhorn
Posts: 6
  • 0
  • 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))
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • 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.
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • 0
  • 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
  • 0
  • 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: 1082
Java Oracle Spring
  • 0
  • 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
  • 0
  • 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: 1082
Java Oracle Spring
  • 0
  • 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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic