Date format problem with Java and MS-Access

R

ruds

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.
 
R

ruds

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");
 
G

GArlington

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...
 
A

Arne Vajhøj

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
 
A

Arne Vajhøj

Lew said:
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
 
A

Arne Vajhøj

Lew said:
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
 
D

David Segall

Arne Vajhøj said:
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.
 
A

Arne Vajhøj

David said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top