Author
Reading from SQL Server
b rag
Greenhorn
Joined: Mar 31, 2005
Posts: 6
posted Apr 08, 2005 13:02:00
0
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))
Steve Morrow
Ranch Hand
Joined: May 22, 2003
Posts: 657
posted Apr 08, 2005 14:15:00
0
Try java.sql.ResultSet.getTimestamp().
Christopher Zinn
Greenhorn
Joined: Nov 03, 2003
Posts: 13
posted Apr 08, 2005 14:31:00
0
I've run into various class-cast problems also with dates and timestamps in JDBC . For me, most of my problems were because I had a java.util.Date on my bean and JDBC returns java.sql.Date (or Timestamp). (I know that java.sql.Date and Timestamp are subclasses of java.util.Date ). I use java.util.Date 's only in my beans, and convert to and from Dates and Timestamps as needed when reading/writing to JDBC. My code, generally looks like this:
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
posted Apr 08, 2005 14:39:00
0
Please stop posting new copies of this thread! Continue the discussion here.
[Jess in Action] [AskingGoodQuestions]
subject: Reading from SQL Server