Re: Problem with DATE - Mailing list pgsql-jdbc

From dmp
Subject Re: Problem with DATE
Date
Msg-id 54B9433B.6070706@ttc-cmc.net
Whole thread Raw
In response to Re: Problem with DATE  (Vinayak <vinpokale@gmail.com>)
Responses Re: Problem with DATE  (Vinayak <vinpokale@gmail.com>)
List 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


pgsql-jdbc by date:

Previous
From: Dave Cramer
Date:
Subject: Re: Problem with DATE
Next
From: Scott Morgan
Date:
Subject: Docs java 1.7 and 1.8