🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.bbs.comp.lang.java
Article #23848

Re: SQL, Dates and MS Access Databases

#23848
From: Joe
Date: Mon, 17 Sep 2001 20:22
46 lines
3450 bytes
I think you need to use a java.sql.Timestamp, I know for MS sql server
you do and I believe I have seen other posts about this problem.
Also I would use a prepared statement with setTimestamp this should
handle the problem with the wrong date.


"Randy K. Secrist" <r.secrist@m.cc.utah.edu> wrote in message news:<zC3p7.63$%W3.128769@news.uswest.net>...
> Help!
> 
> Does anyone know how to get the number of exact days since or before a
> specific time period?  If you think you can help, let me describe what I am
> doing below...
> 
> I am inserting rows into an access database.  One of the columns I am adding
> is a date field.  Normally using Oracle or DB2, I can instantiate a
> java.util.Date, and insert the variable directly in the insert statement,
> and the correct date gets inserted into the database.
> 
> However, in this case, the people I am doing a program for are set on using
> MS Access.  *Sigh*.  The driver throws an exception if I use a
> java.util.Date, and if I use a java.sql.Date it successfully inserts the
> field into the database, but the wrong date is added to the row.  So, after
> experimenation, i noticed that to get the correct date into the database,
> the SQL insert statment must have the date fields is just really a regular
> integer that looks like this:
> 
> 0 being December 30 1899
> 1 being December 31 1899
> 2 being Jan 01, 1900
> 3 being Jan 02, 1900 etc.
> 
> 25569 being Jan 01, 1970
> 
> Since java tracks time in miliseconds from Jan 01 1970 - 12:00 AM being
> around 2703600000 miliseconds, i started to do  this the hard way - to get
> the number of days since 01/01/1900 from the number of miliseconds since
> 1970 - writing all kinds of methods to divide and get the miliseconds right.
> 
> So far this work around seems to work for 1900 to 2100 years, but if I go
> back far in time, say to 1700 it starts getting off by a few days.  For all
> i know it has to do with leap years, and the such.  Basically I don't want
> to write a whole date class just to get the number of days... does anyone
> have solutions that could save me a lot of time and hassle?  I'd really
> appreciate it....
> 
> Randy Secrist
Technical Details
Message-ID: <8e770fbf.0109171222.26c7013f@posting.google.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail
References: <zC3p7.63$%W3.128769@news.uswest.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10a146,5e897627a3332cb9
X-Google-Attributes: gid10a146,public
X-Google-Thread: 111d6b,5e897627a3332cb9
X-Google-Attributes: gid111d6b,public
X-Google-Thread: f6cb0,5e897627a3332cb9
X-Google-Attributes: gidf6cb0,public
X-Google-Thread: 113ae9,5e897627a3332cb9
X-Google-Attributes: gid113ae9,public
X-Google-Thread: f5d71,5e897627a3332cb9
X-Google-Attributes: gidf5d71,public
X-Google-ArrivalTime: 2001-09-17 13:22:59 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail
From: yohan1701@space.com (Joe)
Newsgroups: cn.bbs.comp.lang.java,comp.lang.java,comp.lang.java.help,comp.lang.java.misc,comp.lang.java.programmer
Subject: Re: SQL, Dates and MS Access Databases
Date: 17 Sep 2001 13:22:58 -0700
Organization: http://groups.google.com/
Lines: 46
Message-ID: <8e770fbf.0109171222.26c7013f@posting.google.com>
References: <zC3p7.63$%W3.128769@news.uswest.net>
NNTP-Posting-Host: 207.164.86.180
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1000758179 11267 127.0.0.1 (17 Sep 2001 20:22:59 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: 17 Sep 2001 20:22:59 GMT