Re: Problem with DATE

From: dmp <danap(at)ttc-cmc(dot)net>
To: Vinayak <vinpokale(at)gmail(dot)com>, PostgreSQL JDBC <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Problem with DATE
Date: 2015-01-16 16:58:35
Message-ID: 54B9433B.6070706@ttc-cmc.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Vinayak wrote:
> Hi Dave,
> Thank you for explanation.
>
> I understood that the behavior of date is different in PostgreSQL and Java.
> PostgreSQL DATE type return date part only.
> Java DATE return date and time with timezone.
>> I am guessing what you really want is to just take the date in your Oracle
> db, load it into java and store >it into postgresql without any
> transformation.
>> This would require a custom date type.
> I have created custom date type which return date and time in PostgreSQL.
> postgres=# select now()::date;
> now
> ---------------------------------
> 2015-01-16 10:51:41
> (1 row)
> but still PreparedStatement throws error for date parameter.
>
> -----
> Regards,
> Vinayak,

Hello,

If you are able to perform the conversion of the Oracle Date to a java.sql.Date
type then perhaps instead of trying to force this into a setObject() statement
have you just tried setDate()?

The code you have shown works fine with my application, but not as setObject()

if (columnType.equals("DATE"))
{
java.sql.Date dateValue;

dateString = MyJSQLView_Utils.convertViewDateString_To_DBDateString(

dateTimeFormString,DBTablesPanel.getGeneralDBProperties().getViewDateFormat());

dateValue = java.sql.Date.valueOf(dateString);
prepared_sqlStatement.setDate(i++, dateValue);
}

I know you have said that you do not wish to change your code throughout, but
this may be the easist approach rather then rewriting the driver. You might
have already changed the code in a day's work.

danap.
MyJSQLView Project Manager
dandymadeproductions.com

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Scott Morgan 2015-01-19 10:14:03 Docs java 1.7 and 1.8
Previous Message Dave Cramer 2015-01-16 10:41:05 Re: Problem with DATE