From: Aydın Toprak <aydin.toprak@intengo.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: How to insert "date" as timestamp
Date: Thu, 13 Oct 2005 14:31:30 +0300
Message-ID: <434E4592.8050909@intengo.com> (raw)
In-Reply-To: <434E2477.2080304@mosaic-ag.com>
References: <s34dbd65.061@gwmta.wicourts.gov>
<434E1BE2.2060108@intengo.com>
<434E2477.2080304@mosaic-ag.com>
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)"...
>> <b>(but eclipse say that it can!)</b>
>>
>
> 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.
>
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: aydin.toprak@intengo.com
Subject: Re: How to insert "date" as timestamp
In-Reply-To: <434E4592.8050909@intengo.com>
References: <s34dbd65.061@gwmta.wicourts.gov> <434E1BE2.2060108@intengo.com> <434E2477.2080304@mosaic-ag.com> <434E4592.8050909@intengo.com>
* 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