*
The moose likes JDBC and the fly likes Using setDate(column,Date) to insert date in sybase database 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 » Databases » JDBC
Bookmark "Using setDate(column,Date) to insert date in sybase database" Watch "Using setDate(column,Date) to insert date in sybase database" New topic
Author

Using setDate(column,Date) to insert date in sybase database

Harshil Mehta
Ranch Hand

Joined: Mar 17, 2005
Posts: 64
Hello Ranchers,

I am facing a problem in inserting date-time value in a column of type datetime in table of sybase database.

I am collecting datetime in mm/dd/yyyy hh:mi format in a string variable. Then i convert that to java.util.Date using SimpleDateFormat.

To insert this date to database i am using a CallableStatement call to execute the stored procedure in the database. For that, i am using [B]prepareCall[B] of the connection object.

Now i am writing

statement.setDate(columnIndex, new java.sql.Date(utilDate.getTime())

This code executes properly but in the database table, only date value is stored. The time value is not stored and it shows hh:mi as 00:00 only.

I need to store the time value also.

Is my code wrong in case?
Please advise.

Thanks in advance.

[edited to remove empty code tags]
[ August 07, 2005: Message edited by: Jeanne Boyarsky ]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30136
    
150

Harshil,
You need to call setTimeStamp() instead of setDate(). As you noticed, setDate() only sets the date. setTime() would only set the time and setTimeStamp() sets both.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using setDate(column,Date) to insert date in sybase database
 
Similar Threads
how to handle Null values?
problem while inserting date field in oracle data base
how to change the date,Time format after accessing it from the database
Losing time when manipulating a date time and sending it to database (java.sql.Date)
Sybase text column insert with Hibernate