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 8DCF3D86F4 for ; Thu, 13 Oct 2005 08:31:34 -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 61457-08 for ; Thu, 13 Oct 2005 11:31:30 +0000 (GMT) Received: from xmail04.myhosting.com (xmail04.myhosting.com [168.144.250.218]) by svr1.postgresql.org (Postfix) with ESMTP id AEA36D86EF for ; Thu, 13 Oct 2005 08:31:31 -0300 (ADT) Received: (qmail 18396 invoked from network); 13 Oct 2005 11:31:33 -0000 Received: from unknown (HELO [192.168.1.2]) (Authenticated-user:_aydin.toprak@intengo.com@[85.101.60.52]) (envelope-sender ) by xmail04.myhosting.com (qmail-ldap-1.03) with SMTP for ; 13 Oct 2005 11:31:32 -0000 Message-ID: <434E4592.8050909@intengo.com> Date: Thu, 13 Oct 2005 14:31:30 +0300 From: =?UTF-8?B?QXlkxLFuIFRvcHJhaw==?= User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Re: How to insert "date" as timestamp References: <434E1BE2.2060108@intengo.com> <434E2477.2080304@mosaic-ag.com> In-Reply-To: <434E2477.2080304@mosaic-ag.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.017 required=5 tests=[AWL=0.017] X-Spam-Level: X-Archive-Number: 200510/55 X-Sequence-Number: 13986 Thanks for your help. It was very accurate and worked. Roland Walter wrote: > Aydın Toprak schrieb: > >> Hi, >> >> My Object is java.util.Date ... first of all; >> I make an instance of the Date object >> >> Date date = new Date(); >> >> then >> >> I am wirting the set methods of the preparedstatement as >> >> query.setDate(1,date); >> >> however eclipse gives an error message, which is "The method >> setDate(int, Date) in the type PreparedStatement is not applicable >> for the arguments (int, Date)"... >> (but eclipse say that it can!) >> > > You need to convert java.util.Date to java.sql.Date if you want only > to 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 > 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 = new java.util.Date(System.currentTimeMillis()); > java.sql.Timestamp timestamp = new java.sql.Timestamp(date.getTime()); > > It is the same for the conversion to java.sql.Date. > > Regards, > Roland. >