Hi, I'm new to this newsgroup...
How can I write a date/time to my acces database?
Jdbc only supports java.sql.Date witch doesn't saves the time and
java.sql.time witch doesn't saves the date.
I've also tried to write the date with there long-values(milliseconds) by
setlong(int,long) but then jbdc tells me he doens't support setlong for
acces.
Can someone tell me the right way to write those date into my acces db?
Regards,
BV
Chris - 29 Mar 2004 00:55 GMT
> Hi, I'm new to this newsgroup...
>
[quoted text clipped - 12 lines]
> Regards,
> BV
Hi,
I'm not absolutely sure (I never use Access), but have you tried
java.sql.Timestamp? You can throw a java.util.Date into it (which has
everything from years to seconds), plus a nanoseconds. I assume
Access will discard the nanoseconds part and save the years, months,
days, hours, minutes, and seconds.
- --
Chris
David Harper - 29 Mar 2004 07:02 GMT
> How can I write a date/time to my acces database?
> Jdbc only supports java.sql.Date witch doesn't saves the time and
[quoted text clipped - 5 lines]
>
> Can someone tell me the right way to write those date into my acces db?
You need a two-stage approach. First, create an object of the class
java.util.GregorianCalendar using the constructor which takes six
integer parameters to specify date and time:
public GregorianCalendar(int year,
int month,
int date,
int hour,
int minute,
int second)
Now use the getTimeInMillis member function to extract the time in
milliseconds since the epoch (1970 January 1 00:00:00 Universal Time),
and pass this as the argument to the constructor of a java.sql.Timestamp
object. You can now use the Timestamp object to insert the date and time
into your database.
java.util.GregorianCalendar allows re-use of the object to represent a
different date and time through the "set" function:
public final void set(int year,
int month,
int date,
int hour,
int minute,
int second)
Hope this helps.
David Harper
Cambridge, England