wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Reading from SQL Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

Reading from SQL Server

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))
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

Try java.sql.ResultSet.getTimestamp().
Christopher Zinn
Greenhorn

Joined: Nov 03, 2003
Posts: 13
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: 24183
    
  34

Please stop posting new copies of this thread! Continue the discussion here.


[Jess in Action][AskingGoodQuestions]
 
 
subject: Reading from SQL Server
 
Similar Threads
Copying BLOB from SQL Server 2000 to Oracle 8
Sql optimizer
ClassCaseException
sql server driver
a q about SQL Server 2005 DB and Java