iNET Interactive - Online Advertising Agency
          
  |   Rules
 


Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you would prefer not to see any double-underlined words and corresponding advertisements, please click here.

Go Back  dBforums > Usenet Groups > comp.lang.* > comp.lang.java.databases > Inserting Date

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-30-02, 05:36
Peter Kirk
 
Posts: n/a
Inserting Date

Hi there I am trying to insert a Date object into a database. The date is inserted,
but not the time. Why could this be?

I am using a prepared statement and setDate (the "photo" object in the below contains
a java.util.Date object, from which I create a java.sql.Date object - I am sure there
is a time on this Date object):

stmt.setDate( 4, new java.sql.Date( photo.getDate().getTime() ) );

but on the insert it is only the date that ends up in the DATE column.

Thanks, Peter.
Reply With Quote
  #2  
Old 08-30-02, 05:40
davide
 
Posts: n/a
Re: Inserting Date

Peter Kirk <peter_kirk@alpha-gruppen.dk> wrote:
  > The date is inserted, but not the time. Why could this be?

Check what kind of field you are insertint into. If it's a DATE field maybe the time
is set to 0 automatically.

Davide
Reply With Quote
  #3  
Old 08-30-02, 06:52
Peter Kirk
 
Posts: n/a
Re: Inserting Date

<davide@yahoo.com> wrote in message news:akneip$1k61g4$4@ID-18487.news.dfncis.de...
  > Peter Kirk <peter_kirk@alpha-gruppen.dk> wrote:
     > > The date is inserted, but not the time. Why could this be?
  > Check what kind of field you are insertint into. If it's a DATE field maybe the
  > time is set to 0 automatically.
  > Davide

Hi, thanks for the reply. Yes, the field is a DATE field. Do you think the database
might just set the time to 0?

I can get it to work if I make a timestamp instead: stmt.setTimestamp( 4, new
java.sql.Timestamp( photo.getDate().getTime() ));

This inserts as I expect into the DATE field.

Peter.
Reply With Quote
  #4  
Old 08-30-02, 06:56
davide
 
Posts: n/a
Re: Inserting Date

Peter Kirk <peter_kirk@alpha-gruppen.dk> wrote:
  > Yes, the field is a DATE field. Do you think the database might just set the
  > time to 0?

It's possible, or he just does not show the time because it's a DATE field. Try using
a TimeStamp or DATETIME field type.

  > This inserts as I expect into the DATE field.

Then the driver cut off the time when you are using Date. Use Timestamp instead.

Davide
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump