Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / March 2004

Tip: Looking for answers? Try searching our database.

jdbc, acces and dates

Thread view: 
Bart Verdonck - 28 Mar 2004 22:36 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.