Date format problem with Java and MS-Access

Discussion in 'Java' started by ruds, Jul 14, 2008.

  1. ruds

    ruds Guest

    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.
     
    ruds, Jul 14, 2008
    #1
    1. Advertising

  2. ruds

    ruds Guest

    On Jul 14, 8:56 am, Lew <> 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");
     
    ruds, Jul 14, 2008
    #2
    1. Advertising

  3. ruds

    GArlington Guest

    On Jul 14, 4:35 am, 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.


    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...
     
    GArlington, Jul 14, 2008
    #3
  4. ruds

    Arne Vajhøj Guest

    ruds wrote:
    > On Jul 14, 8:56 am, Lew <> 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
     
    Arne Vajhøj, Jul 15, 2008
    #4
  5. 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
     
    Arne Vajhøj, Jul 15, 2008
    #5
  6. 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
     
    Arne Vajhøj, Jul 19, 2008
    #6
  7. ruds

    David Segall Guest

    Arne Vajhøj <> 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.
     
    David Segall, Jul 20, 2008
    #7
  8. ruds

    Arne Vajhøj Guest

    David Segall wrote:
    > Arne Vajhøj <> 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
     
    Arne Vajhøj, Jul 21, 2008
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Candy
    Replies:
    2
    Views:
    1,177
    Janaka
    Feb 18, 2004
  2. DC
    Replies:
    5
    Views:
    3,021
    Brendan Reynolds
    Jul 1, 2005
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,300
    Michael Borgwardt
    May 30, 2004
  4. laredotornado
    Replies:
    2
    Views:
    881
    laredotornado
    Dec 4, 2009
  5. Une bévue

    problem with date and date/format

    Une bévue, Mar 10, 2006, in forum: Ruby
    Replies:
    3
    Views:
    113
    Une bévue
    Mar 12, 2006
Loading...

Share This Page