From: Andreas Reichel <andreas@manticore-projects.com>
To: Dave Cramer <pg@fastcrypt.com>
Cc: List <pgsql-jdbc@postgresql.org>
Subject: Re: Timestamp vs. Java Date/Timestamp
Date: Wed, 06 Feb 2013 02:38:21 +0000
Message-ID: <1360118301.14635.16.camel@localhost> (raw)
In-Reply-To: <CADK3HHJDvnHzcbEu2CMJ7g_riuMTi6D-=1mdvc+T-9DYEidvJA@mail.gmail.com>
References: <1360043227.14635.9.camel@localhost>
<CADK3HHJDvnHzcbEu2CMJ7g_riuMTi6D-=1mdvc+T-9DYEidvJA@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>
Hi Dave,
I tried setObject() handing over java.util.Date or java.sql.Date.
Furthermore I tried setDate() (which enforces java.sql.Date) and
setTimestamp (which enforces java,sql.Timestamp). It all failed the same
way.
Best regards
Andreas
On Tue, 2013-02-05 at 09:42 -0500, Dave Cramer wrote:
> Andreas,
>
>
> What are you using to setTimestamp in the prepared statement ? setDate
> or setTimestamp ?
>
> Dave Cramer
>
> dave.cramer(at)credativ(dot)ca
> http://www.credativ.ca
>
>
>
> On Tue, Feb 5, 2013 at 12:47 AM, Andreas Reichel
> <andreas@manticore-projects.com> wrote:
> Dear List,
>
> the last day I had a hard time figuring out how to hand over
> timestamps
> using prepared statements.
>
> The table looks like this:
>
> trader=# \d trader.tickdata
> Table "trader.tickdata"
> Column | Type | Modifiers
> -------------------+-----------------------------+-----------
> id_instrument | smallint | not null
> id_stock_exchange | smallint | not null
> timestamp | timestamp without time zone | not null
> price | double precision | not null
>
>
> Now I would like to retrieve ticks using a prepared statement
> like this:
>
> -- GET TICKDATA
> select
> t1.id_instrument,
> t1.id_stock_exchange,
> t1."timestamp",
> t1.price,
> coalesce(t2.quantity,0) quantity
> from
> trader.tickdata t1
> left join trader.volumedata t2
> ON (t1.id_instrument=t2.id_instrument AND
> t1.id_stock_exchange=t2.id_stock_exchange AND
> t1."timestamp"=t2."timestamp")
> where
> t1.id_instrument= ?
> AND t1.id_stock_exchange= ?
> --careful with TIMEZONE here!
> AND t1."timestamp">= ?
> AND t1."timestamp"<= ?
> ORDER BY t1."timestamp" ASC;
>
> If I hand over java.util.Date or java.sql.Date or
> java.sql.Timestamp the
> query will be executed but returns the wrong number of
> records;
>
> However, if I change the query into:
> -- GET TICKDATA
> select
> t1.id_instrument,
> t1.id_stock_exchange,
> t1."timestamp",
> t1.price,
> coalesce(t2.quantity,0) quantity
> from
> trader.tickdata t1
> left join trader.volumedata t2
> ON (t1.id_instrument=t2.id_instrument AND
> t1.id_stock_exchange=t2.id_stock_exchange AND
> t1."timestamp"=t2."timestamp")
> where
> t1.id_instrument= ?
> AND t1.id_stock_exchange= ?
> --careful with TIMEZONE here!
> AND t1."timestamp">= cast(? as timestamp)
> AND t1."timestamp"<= cast(? as timestamp)
> ORDER BY t1."timestamp" ASC;
>
> and hand over a formated date "yyyy-MM-dd HH:mm:ss" it works
> correctly.
> Now I have on simple questions please:
>
> What is the correct way to hand over a Java Date parameter
> (avoiding the
> double String manipulation)?
>
> Thank you and best regards!
> Andreas
>
>
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>
>
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: andreas@manticore-projects.com, pg@fastcrypt.com
Subject: Re: Timestamp vs. Java Date/Timestamp
In-Reply-To: <1360118301.14635.16.camel@localhost>
References: <1360043227.14635.9.camel@localhost> <CADK3HHJDvnHzcbEu2CMJ7g_riuMTi6D-=1mdvc+T-9DYEidvJA@mail.gmail.com> <1360118301.14635.16.camel@localhost>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox