From: im i <linimi@gmail.com>
To: Dave Cramer <pg@fastcrypt.com>
Cc: Peter.Zoche@materna.de
Cc: pgsql-jdbc@postgresql.org
Subject: Re: newbie question to setTimestamp( int parameterIndex, Timestamp x, Calendar cal)
Date: Tue, 19 Jul 2005 13:25:36 +0200
Message-ID: <f739e48505071904259b8f1e1@mail.gmail.com> (raw)
In-Reply-To: <1C7D4610-DD9B-4D42-BE3C-B2257D099D2D@fastcrypt.com>
References: <3617A3C21370D045B75C0A40A7A6530D0B37E17E@ntexc2buc.do-office.buc.materna.com>
<1C7D4610-DD9B-4D42-BE3C-B2257D099D2D@fastcrypt.com>
Hi,
This is 2 static method what convert from/to TimeStamp/GregorianCalendar:
public static Timestamp Gregorian2Timestamp(GregorianCalendar
gregorianCalendar) {
return (gregorianCalendar == null ? null : new
java.sql.Timestamp(gregorianCalendar.getTimeInMillis()));
}
public static GregorianCalendar Timestamp2Gregorian(Timestamp timestamp) {
GregorianCalendar result = null;
if (timestamp != null) {
result = new GregorianCalendar();
result.setTime(new Date(timestamp.getTime()));
}
return (result);
}
linimi
On 7/19/05, Dave Cramer <pg@fastcrypt.com> wrote:
> Peter,
>
> Timestamp is the actual time that you want to store. The calendar
> object is there if you want to use a different calendar to reference
> the timestamp to ?
>
> Dave
> On 19-Jul-05, at 6:49 AM, Peter.Zoche@materna.de wrote:
>
> > Hi all!
> >
> > I am new to postgresql and i have the following question:
> >
> > how does setTimestamp( int parameterIndex, Timestamp x, Calendar
> > cal) work?
> > why is there a parameter Timestamp? I have a Calendar in my java
> > code and I
> > would like to store it in the database via a PreparedStatement. So for
> > example:
> >
> > I have the following table:
> >
> > CREATE TABLE dates( date TIMESTAMP WITH TIME ZONE );
> >
> > Java code:
> >
> > PreparedStatement ps = connection.prepareStatement( "INSERT INTO
> > dates (date) VALUES ?");
> > ps.setTimestamp( 1, new Timestamp(), myCalendar );
> >
> > Is this correct? But why is there a Timestamp parameter? It seems
> > clear that
> > the
> > calendar should be converted into a timestamp because the method is
> > named
> > setTimestamp. I am really confused about this.
> >
> > Please help
> >
> > Peter
> >
> > ---------------------------(end of
> > broadcast)---------------------------
> > TIP 4: Have you searched our list archives?
> >
> > http://archives.postgresql.org
> >
> >
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
>
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: linimi@gmail.com, pg@fastcrypt.com, Peter.Zoche@materna.de
Subject: Re: newbie question to setTimestamp( int parameterIndex, Timestamp x, Calendar cal)
In-Reply-To: <f739e48505071904259b8f1e1@mail.gmail.com>
References: <3617A3C21370D045B75C0A40A7A6530D0B37E17E@ntexc2buc.do-office.buc.materna.com> <1C7D4610-DD9B-4D42-BE3C-B2257D099D2D@fastcrypt.com> <f739e48505071904259b8f1e1@mail.gmail.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