• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic