🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: SQL, Dates and MS Access Databases

#23847
From: Steve Horsley
Date: Mon, 17 Sep 2001 11:19
53 lines
3747 bytes
I have successfully used java.sql.Date.toString() and placed this in
SQL requests to Access. It comes out in yyyy-mm-dd format, which you 
have to surround with '#' characters, like this:
  #2001-09-17#

The other problem that kept me stumped for several days was that the
table had a column called "Date". I did not realise that DATE is a 
reserved keyword in SQL, so I kept getting syntax errors. The fix is 
to use the column name "[Date]" - surround it in square brackets.

Hope this helps.
Steve.

"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: <aa25b022.0109170319.7a1ab58e@posting.google.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.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: f5d71,5e897627a3332cb9
X-Google-Attributes: gidf5d71,public
X-Google-Thread: 111d6b,5e897627a3332cb9
X-Google-Attributes: gid111d6b,public
X-Google-Thread: f6cb0,5e897627a3332cb9
X-Google-Attributes: gidf6cb0,public
X-Google-Thread: 10a146,5e897627a3332cb9
X-Google-Attributes: gid10a146,public
X-Google-Thread: 113ae9,5e897627a3332cb9
X-Google-Attributes: gid113ae9,public
X-Google-ArrivalTime: 2001-09-17 04:19:13 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!postnews1.google.com!not-for-mail
From: steve.horsley@cwcom.cwplc.com (Steve Horsley)
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 04:19:08 -0700
Organization: http://groups.google.com/
Lines: 53
Message-ID: <aa25b022.0109170319.7a1ab58e@posting.google.com>
References: <zC3p7.63$%W3.128769@news.uswest.net>
NNTP-Posting-Host: 194.6.81.93
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1000725548 2960 127.0.0.1 (17 Sep 2001 11:19:08 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: 17 Sep 2001 11:19:08 GMT