Re: Problem with DATE

From: Lachezar Dobrev <l(dot)dobrev(at)gmail(dot)com>
To: Vinayak <vinpokale(at)gmail(dot)com>
Cc: List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Problem with DATE
Date: 2015-01-06 16:51:09
Message-ID: CA+xsaB3ovLRj_75j4hyMC+rB+JbV9vVYUgRvnm4+KcOr5-e8KQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Try connecting to PostgreSQL using the version 2 protocol (older version).
jdbc:postgresql:...?protocolVersion=2

I've had (different) problems with dates in PostgreSQL due to the
fact, that PostgreSQL has two date formats (with and without a Time
Zone), and there are some shenanigans detecting what type the date
would have to be, and ends up using neither, blah blah (can't
remember).

2015-01-06 14:21 GMT+02:00 Vinayak <vinpokale(at)gmail(dot)com>:
> Hi,
> The following java code works fine using Oracle jdbc driver.
> It works fine in PostgreSQL for BigDecimal and String etc. but for date it
> throws error.
>
> example:
> ps = conn.prepareStatement("SELECT ?, ?, ?,?");
> ps.setObject(1, new String("1.2"));
> ps.setObject(2, new BigDecimal("1.2"));
> ps.setObject(3, new String("2014-01-11 33:22:11"));
> ps.setObject(4, Date.valueOf("2014-01-11"));
>
> org.postgresql.util.PSQLException: ERROR: could not determine data type of
> parameter $4
> at
> org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
> at
> org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
> at
> org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
> at
> org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:559)
> at
> org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
> at
> org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
> at TestSetDate.main(TestSetDate.java:39)
>
> The above problem is solved after typecasting the 4th argument to date.
> ps = conn.prepareStatement("SELECT ?, ?, ?,?::date");
> OR
> ps = conn.prepareStatement("SELECT ?, ?, ?,date(?)");
>
> Is there any possibility to add something like PGdate in PostgreSQL jdbc
> driver?
> so that during migration from Oracle to PostgreSQL,there is no need to edit
> the java code.
>
> Regards,
> Vinayak
>
>
>
> -----
> Regards,
> Vinayak,
>
> --
> View this message in context: http://postgresql.nabble.com/Problem-with-DATE-tp5833008.html
> Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Alexis Meneses 2015-01-06 19:54:23 Re: Unregistering the driver from DriverManager
Previous Message Dave Cramer 2015-01-06 13:43:20 Re: Problem with DATE