Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U2y01-0007Qx-JH for pgsql-jdbc@arkaria.postgresql.org; Wed, 06 Feb 2013 05:56:49 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1U2y00-000684-Sx for pgsql-jdbc@arkaria.postgresql.org; Wed, 06 Feb 2013 05:56:48 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U2uuA-0001de-Cs for pgsql-jdbc@postgresql.org; Wed, 06 Feb 2013 02:38:34 +0000 Received: from moutng.kundenserver.de ([212.227.17.9]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U2uu8-0006uJ-2b for pgsql-jdbc@postgresql.org; Wed, 06 Feb 2013 02:38:33 +0000 Received: from [192.168.0.10] (node-79e.pool-1-4.dynamic.totbb.net [1.4.164.194]) by mrelayeu.kundenserver.de (node=mrbap4) with ESMTP (Nemesis) id 0McEmF-1ULpEU2vIN-00JNTk; Wed, 06 Feb 2013 03:38:27 +0100 Message-ID: <1360118301.14635.16.camel@localhost> Subject: Re: Timestamp vs. Java Date/Timestamp From: Andreas Reichel To: Dave Cramer Cc: List Date: Wed, 06 Feb 2013 02:38:21 +0000 In-Reply-To: References: <1360043227.14635.9.camel@localhost> Content-Type: text/plain; charset="us-ascii" X-Mailer: Evolution 3.6.3 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:3d8o2u3OYHj6dEj8MBTcYvuBociTG0Lix2RkGSibbIp 52bns9euqA200csRwriZr8FwB3YZza84MoX1T+ZjL/lykhlHfU sEW9iMDMQiSTKFpmHzSO0t3o3oTVvEA0yHfcamNlDfMzUy1uH8 VOjFECQOnS8opG67Hx5k/11/wBr0LLyaVO3BfEvaQ0zB9gFP9r 26foSbDMTG2EE5xylm6L43aiYfH71utyur7PDNUN8ACaROPpDk ZB9ftloh+It0Hf4w7wvD32DUizXsXdPFDf7AqPVNhIt94tvRFw pdMo51c7hjZUmVFQ1JdRgrmBMKqoIMmOX/25OOwrIXZloseJzV P3xbijIBfe9TiKSuwYPiuR1WFjiekpdoahrLBalHQ X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org 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 > 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