Re: insert daterange field value

From: Artem Pronchakov <artem(dot)pronchakov(at)gmail(dot)com>
To: List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: insert daterange field value
Date: 2014-03-06 12:32:54
Message-ID: CANt3_r51nwyYryu2zhGjL4KLb_7u1N1RxXskzeFLxkJG8F9Azw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Thank you. It worked.

On Thu, Mar 6, 2014 at 4:27 PM, Sehrope Sarkuni <sehrope(at)jackdb(dot)com> wrote:

> > Does anyone have a solution for inserting daterange? What stm.setXXX
> should I use? Or maybe I cannot do that because JDBC Driver does not have
> daterange support... Maybe there is a third solution?
>
> You need to specify the cast in your SQL and then bind the parameter
> with setObject(...).
>
> String value = "[2014-01-02,2014-01-04]";
> String sql = "INSERT INTO date_range_test (some_field) VALUES
> (?::daterange)";
> PreparedStatement stmt = conn.prepareStatement(sql);
> stmt.setObject(1, value);
> stmt.execute();
>
> > My PostgreSQL JDBC Driver:
> >
> > <dependency>
> > <groupId>postgresql</groupId>
> > <artifactId>postgresql</artifactId>
> > <version>8.4-701.jdbc4</version>
> > </dependency>
>
> I haven't tried this with the older 8.4 driver but the code above
> works fine with the latest 9.3 driver.
>
> It might work with the older driver as well but you really should
> upgrade your JDBC driver to a more recent version.
>
> The newer driver supports both old (8.4+) and new versions of
> PostgreSQL so there's no real reason not to use it.
>
> Regards,
> Sehrope Sarkuni
> Founder & CEO | JackDB, Inc. | http://www.jackdb.com/
>

--
Artem Pronchakov
Senior Software Developer
Gemini-Systems Russia
My PGP public key<https://keyserver2.pgp.com/vkd/DownloadKey.event?keyid=0xA60DA7F35C011396>

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Naoya Anzai 2014-03-07 04:18:56 A prepared statement ERROR due to EMPTY_QUERY is defined as a static Instance.
Previous Message Stephen Nelson 2014-03-06 12:31:47 Fwd: insert daterange field value