File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes JDBC setDate (oracle driver). Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "JDBC setDate (oracle driver)." Watch "JDBC setDate (oracle driver)." New topic

JDBC setDate (oracle driver).


Joined: May 14, 2003
Posts: 3
I have a column with "DATE" as datatype ..As part of a batch process I need to insert the start date and time into that (YYYY-MM-DD HH24:MI:SS).
If i use just the Statement and the to_date function in the "values" clause it works ..but this is an existing application using "Prepared Statement" and we're migrating from sybase to oracle. When I am trying to use the setDate function it is just inserting the date part and putting zeros (00:00:00) for time part where as in sybase just the setString was taking care of everything ... Any suggestions please ...
Andy Bowes
Ranch Hand

Joined: Jan 14, 2003
Posts: 171
Have you tried using the setTimestamp() method on the Prepared Statement ?
java.util.Date now = new java.util.Date();
ps.setTimestamp( new java.sql.Timestamp(now.getTime()) );
I think that the setDate() method only sets the date portion of the DateTime column.

Andy Bowes<br />SCJP, SCWCD<br />I like deadlines, I love the whoosing noise they make as they go flying past - Douglas Adams

Joined: May 14, 2003
Posts: 3
Thanks Andy .. that works..
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: JDBC setDate (oracle driver).
jQuery in Action, 3rd edition