f



Date format problem with Java and MS-Access

Hi,
I'm using access as database for my Java applications.I have specified
the Date format in Access as d/m/yyyy.
But when I retrieve the data from the database, I get for some dates
as m/d/yyyy format(for dates 1-10 specially).
I have even formatted my dates using SimpleDateFormat in my jsp files
as d/m/yyyy, but I'm still not able to get the dates in the correct
format.

Please help.
0
rudranee (142)
7/14/2008 3:35:01 AM
comp.lang.java.programmer 52714 articles. 1 followers. Post Follow

10 Replies
643 Views

Similar Articles

[PageSpeed] 52

ruds wrote:
> Hi,
> I'm using access as database for my Java applications.I have specified
> the Date format in Access as d/m/yyyy.
> But when I retrieve the data from the database, I get for some dates
> as m/d/yyyy format(for dates 1-10 specially).
> I have even formatted my dates using SimpleDateFormat in my jsp files
> as d/m/yyyy, but I'm still not able to get the dates in the correct
> format.
> 
> Please help.

Hard to do without more information.

What JDBC driver are you using to connect to Access?

Will you provide an SSCCE that demonstrates the problem?  I'm particularly 
interested in the PreparedStatement#setDate() and ResultSet#getDate() calls, 
and how you use SimpleDateFormat on those.

-- 
Lew
This post contains two requests for information, with considerable detail 
needed to fulfill the second request.  You will know if you answered those 
requests by whether you have provided two pieces of information.
0
lew (2468)
7/14/2008 3:56:28 AM
On Jul 14, 8:56 am, Lew <l...@lewscanon.com> wrote:
> ruds wrote:
> > Hi,
> > I'm using access as database for my Java applications.I have specified
> > the Date format in Access as d/m/yyyy.
> > But when I retrieve the data from the database, I get for some dates
> > as m/d/yyyy format(for dates 1-10 specially).
> > I have even formatted my dates using SimpleDateFormat in my jsp files
> > as d/m/yyyy, but I'm still not able to get the dates in the correct
> > format.
>
> > Please help.
>
> Hard to do without more information.
>
> What JDBC driver are you using to connect to Access?
>
> Will you provide an SSCCE that demonstrates the problem?  I'm particularly
> interested in the PreparedStatement#setDate() and ResultSet#getDate() calls,
> and how you use SimpleDateFormat on those.
>
> --
> Lew
> This post contains two requests for information, with considerable detail
> needed to fulfill the second request.  You will know if you answered those
> requests by whether you have provided two pieces of information.

1. I'm using the JDBC-ODBC driverto connect to Access.
2. for inserting the date I'm just inserting the string equivalent of
the date and while retriving I'm using :
    java.sql.Date submit_date=rs.getDate(14);
   date=df.format(submit_date);
3. where format is;
  SimpleDateFormat df=new SimpleDateFormat("M/dd/yyyy");
0
rudranee (142)
7/14/2008 9:08:38 AM
On Jul 14, 4:35 am, ruds <rudra...@gmail.com> wrote:
> Hi,
> I'm using access as database for my Java applications.I have specified
> the Date format in Access as d/m/yyyy.
> But when I retrieve the data from the database, I get for some dates
> as m/d/yyyy format(for dates 1-10 specially).
> I have even formatted my dates using SimpleDateFormat in my jsp files
> as d/m/yyyy, but I'm still not able to get the dates in the correct
> format.
>
> Please help.

I may be mistaken, but AFAIK Date object does NOT store any formatting
=> it is neither d/m/yyyy, nor yyyy/m/d [nor any other format
combination], Date object is simply a Long numeric representation of
the time elapsed since the epoch...
So, all the formatting problems are on the client side and are related
to system/viewer configuration...
0
garlington (117)
7/14/2008 10:07:46 AM
Lew wrote:
>> What JDBC driver are you using to connect to Access?
>>
>> Will you provide an SSCCE that demonstrates the problem?  I'm particularly
>> interested in the PreparedStatement#setDate() and ResultSet#getDate() calls,
>> and how you use SimpleDateFormat on those.

ruds wrote:
> 1. I'm using the JDBC-ODBC driverto connect to Access.

Ouch.

Then again, you're using Access, so it was already ouch.

> 2. for inserting the date I'm just inserting the string equivalent of

That is likely the problem.  You should insert the date directly.

You don't show the code (apparently you decided not to provide an SSCCE for 
some bizarre, unknowable reason - did you even know what I was requesting?  A 
couple minutes googling would have found <http://pscode.org/sscce.html> or 
similar) for the insertion, but dollars to doughnuts that's the issue.

It is rather hard to diagnose a problem when you keep refusing to provide the 
evidence.

> the date and while retriving I'm using :
>     java.sql.Date submit_date=rs.getDate(14);
>    date=df.format(submit_date);
> 3. where format is;
>   SimpleDateFormat df=new SimpleDateFormat("M/dd/yyyy");

Have you examined 'submit_date' directly to see if it even represents the date 
that you think it does?

What date does 'submit_date' represent, based on checking it?  (Don't assume, 
verify.)

Read <http://pscode.org/sscce.html>.

-- 
Lew
0
lew (2468)
7/14/2008 12:28:49 PM
ruds wrote:
> On Jul 14, 8:56 am, Lew <l...@lewscanon.com> wrote:
>> ruds wrote:
>>> I'm using access as database for my Java applications.I have specified
>>> the Date format in Access as d/m/yyyy.
>>> But when I retrieve the data from the database, I get for some dates
>>> as m/d/yyyy format(for dates 1-10 specially).
>>> I have even formatted my dates using SimpleDateFormat in my jsp files
>>> as d/m/yyyy, but I'm still not able to get the dates in the correct
>>> format.

>> Will you provide an SSCCE that demonstrates the problem?  I'm particularly
>> interested in the PreparedStatement#setDate() and ResultSet#getDate() calls,
>> and how you use SimpleDateFormat on those.

> 2. for inserting the date I'm just inserting the string equivalent of
> the date and while retriving I'm using :
>     java.sql.Date submit_date=rs.getDate(14);
>    date=df.format(submit_date);
> 3. where format is;
>   SimpleDateFormat df=new SimpleDateFormat("M/dd/yyyy");

Lew's question was a "friendly trick question" !

His point was that you should be using PreparedStatement.setDate with
a binary Date object instead of formatting the Date to a String and
concatenate that into the SQL string.

When you do that then the JDBC driver will handle the date formats
for you without you having to worry about anything.

Arne
0
arne6 (9808)
7/15/2008 12:24:17 AM
Lew wrote:
> ruds wrote:
>> 1. I'm using the JDBC-ODBC driverto connect to Access.
> 
> Ouch.
> 
> Then again, you're using Access, so it was already ouch.

Considering that MS does not provide a JDBC driver
for MS Access, then the number of possible drivers is
rather limited !

(at least if expensive commercial packages are not
an option)

Arne
0
arne6 (9808)
7/15/2008 12:26:51 AM
Arne Vajhøj wrote:
> Lew wrote:
>> ruds wrote:
>>> 1. I'm using the JDBC-ODBC driverto connect to Access.
>>
>> Ouch.
>>
>> Then again, you're using Access, so it was already ouch.
> 
> Considering that MS does not provide a JDBC driver
> for MS Access, then the number of possible drivers is
> rather limited !
> 
> (at least if expensive commercial packages are not
> an option)

Yes, that is the reason for the double "ouch".

Considering the availability of Derby (a.k.a., Java DB, the one that comes 
free with every copy of the JDK these days), PostgreSQL and other relatively 
easy-to-use, free RDBMSes, one wonders what traps the OP into Access and the 
non-availability of a JDBC driver.

-- 
Lew
0
lew (2468)
7/15/2008 3:40:00 AM
Lew wrote:
> Arne Vajhøj wrote:
>> Lew wrote:
>>> ruds wrote:
>>>> 1. I'm using the JDBC-ODBC driverto connect to Access.
>>>
>>> Ouch.
>>>
>>> Then again, you're using Access, so it was already ouch.
>>
>> Considering that MS does not provide a JDBC driver
>> for MS Access, then the number of possible drivers is
>> rather limited !
>>
>> (at least if expensive commercial packages are not
>> an option)
> 
> Yes, that is the reason for the double "ouch".
> 
> Considering the availability of Derby (a.k.a., Java DB, the one that 
> comes free with every copy of the JDK these days), PostgreSQL and other 
> relatively easy-to-use, free RDBMSes, one wonders what traps the OP into 
> Access and the non-availability of a JDBC driver.

MS Access is much easier to work with than Derby.

Arne
0
arne6 (9808)
7/19/2008 6:01:59 PM
Arne Vajh�j <arne@vajhoej.dk> wrote:

>Lew wrote:
>> Arne Vajh�j wrote:
>>> Lew wrote:
>>>> ruds wrote:
>>>>> 1. I'm using the JDBC-ODBC driverto connect to Access.
>>>>
>>>> Ouch.
>>>>
>>>> Then again, you're using Access, so it was already ouch.
>>>
>>> Considering that MS does not provide a JDBC driver
>>> for MS Access, then the number of possible drivers is
>>> rather limited !
>>>
>>> (at least if expensive commercial packages are not
>>> an option)
>> 
>> Yes, that is the reason for the double "ouch".
>> 
>> Considering the availability of Derby (a.k.a., Java DB, the one that 
>> comes free with every copy of the JDK these days), PostgreSQL and other 
>> relatively easy-to-use, free RDBMSes, one wonders what traps the OP into 
>> Access and the non-availability of a JDBC driver.
>
>MS Access is much easier to work with than Derby.
You can't compare the two. In fact, you can use Microsoft Access as a
GUI for Derby although I prefer to use OpenOffice Base. Base is
comparable to Access including a built in database engine and the
option to use any database that has a suitable driver. 
0
david7254 (239)
7/20/2008 5:48:06 AM
David Segall wrote:
> Arne Vajh�j <arne@vajhoej.dk> wrote:
>> Lew wrote:
>>> Arne Vajh�j wrote:
>>>> Lew wrote:
>>>>> ruds wrote:
>>>>>> 1. I'm using the JDBC-ODBC driverto connect to Access.
>>>>> Ouch.
>>>>>
>>>>> Then again, you're using Access, so it was already ouch.
>>>> Considering that MS does not provide a JDBC driver
>>>> for MS Access, then the number of possible drivers is
>>>> rather limited !
>>>>
>>>> (at least if expensive commercial packages are not
>>>> an option)
>>> Yes, that is the reason for the double "ouch".
>>>
>>> Considering the availability of Derby (a.k.a., Java DB, the one that 
>>> comes free with every copy of the JDK these days), PostgreSQL and other 
>>> relatively easy-to-use, free RDBMSes, one wonders what traps the OP into 
>>> Access and the non-availability of a JDBC driver.
>> MS Access is much easier to work with than Derby.
> You can't compare the two.

Non the less people do so.

>               In fact, you can use Microsoft Access as a
> GUI for Derby although I prefer to use OpenOffice Base. Base is
> comparable to Access including a built in database engine and the
> option to use any database that has a suitable driver. 

Derby is just a database. Access is both a database and a
database admin tool and a database app development tool.

Access is much easier to work with than only Derby.

You can achieve similar functionality by Derby adding
other stuff on top of it.

But why should anyone want to install Derby + Access +
an ODBC driver for Derby (which is a bit la la topic)
instead of just installing Access ?

(if Access meet the requirements as database backend, which
it will for toy size usage - at least in other languages
than Java due to the lack of a JDBC driver)

Arne
0
arne6 (9808)
7/21/2008 2:47:41 AM
Reply: