X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4F2CDD8585 for ; Thu, 13 Oct 2005 06:16:13 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 30440-10 for ; Thu, 13 Oct 2005 09:16:08 +0000 (GMT) Received: from mosaic02.mosaic.de (mosaic02.mosaic.de [195.247.16.18]) by svr1.postgresql.org (Postfix) with ESMTP id 83D41D84B1 for ; Thu, 13 Oct 2005 06:16:09 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mosaic02.mosaic.de (Postfix) with ESMTP id 0EAC57790A; Thu, 13 Oct 2005 11:17:13 +0200 (CEST) Received: from mosaic02.mosaic.de ([127.0.0.1]) by localhost (mosaic02.mosaic-ag.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 26633-04; Thu, 13 Oct 2005 11:17:11 +0200 (CEST) Received: by mosaic02.mosaic.de (Postfix, from userid 10) id DEDF6778BD; Thu, 13 Oct 2005 11:17:11 +0200 (CEST) Received: from [172.17.1.87] (aupc287.mosaic-ag.com [172.17.1.87]) by mailsrv.mosaic-ag.com (Postfix) with ESMTP id B2A52562C9; Thu, 13 Oct 2005 11:10:15 +0200 (CEST) Message-ID: <434E2477.2080304@mosaic-ag.com> Date: Thu, 13 Oct 2005 11:10:15 +0200 From: Roland Walter User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; de-AT; rv:1.7.5) Gecko/20041217 X-Accept-Language: de-DE,de,en MIME-Version: 1.0 To: =?UTF-8?B?QXlkxLFuIFRvcHJhaw==?= Cc: pgsql-jdbc@postgresql.org Subject: Re: How to insert "date" as timestamp References: <434E1BE2.2060108@intengo.com> In-Reply-To: <434E1BE2.2060108@intengo.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: mosaic-ag.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.07 required=5 tests=[AWL=0.070] X-Spam-Level: X-Archive-Number: 200510/53 X-Sequence-Number: 13984 Ayd=C4=B1n Toprak schrieb: > Hi, >=20 > My Object is java.util.Date ... first of all; > I make an instance of the Date object >=20 > Date date =3D new Date(); >=20 > then >=20 > I am wirting the set methods of the preparedstatement as >=20 > query.setDate(1,date); >=20 > however eclipse gives an error message, which is "The method=20 > setDate(int, Date) in the type PreparedStatement is not applicable for=20 > the arguments (int, Date)"... > (but eclipse say that it can!) >=20 You need to convert java.util.Date to java.sql.Date if you want only to=20 store the date without the time in a database field DATE. Then you can use setDate(). If you want to store it in a database field TIMESTAMP you must convert=20 the java.util.Date to java.sql.Timestamp. Then you can use query.setTimestamp(1, timestamp); If you use setDate with an java.sql.Date here, you loose the information of the time, even if the Database field is of the type TIMESTAMP. The conversion works as the following, i. e.: java.util.Date date =3D new java.util.Date(System.currentTimeMillis()); java.sql.Timestamp timestamp =3D new java.sql.Timestamp(date.getTime()); It is the same for the conversion to java.sql.Date. Regards, Roland. --=20 Roland Walter phone: +49 (0) 22 25 / 88 2-41 1 MOSAIC SOFTWARE AG fax: +49 (0) 22 25 / 88 2-20 1 Am Pannacker 3 mailto: rwa (at) mosaic-ag (dot) com D-53340 Meckenheim http://www.mosaic-ag.com ------- L E G A L D I S C L A I M E R --------- Die Informationen in dieser Nachricht sind vertraulich und ausschliesslich fuer den Adressaten bestimmt. Kenntnisnahme durch Dritte ist unzulaessig. Die Erstellung von Kopien oder das Weiterleiten an weitere, nicht originaere und benannte Adressaten ist nicht vorgesehen und kann ungesetzlich sein. Die Meinungen in dieser Nachricht stellen lediglich die Meinungen des Senders dar. Falls Sie vermuten, dass diese Nachricht veraendert wurde, setzen Sie sich mit dem Absender in Verbindung. Der Absender uebernimmt ohne weitere Ueberpruefung keine Verantwortung fuer die Richtigkeit und Vollstaendigkeit des Inhalts. Unbefugte Empfaenger werden gebeten, die Vertraulichkeit der Nachricht zu wahren und den Absender sofort ueber einen Uebertragungsfehler zu informieren. ------------------------------------------------------