pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feednewbie question to setTimestamp( int parameterIndex, Timestamp x, Calendar cal)
4+ messages / 3 participants
[nested] [flat]
* newbie question to setTimestamp( int parameterIndex, Timestamp x, Calendar cal)
@ 2005-07-19 10:49 Peter.Zoche@materna.de
2005-07-19 11:00 ` Re: newbie question to setTimestamp( int parameterIndex, Timestamp x, Calendar cal) Dave Cramer <pg@fastcrypt.com>
0 siblings, 1 reply; 4+ messages in thread
From: Peter.Zoche@materna.de @ 2005-07-19 10:49 UTC (permalink / raw)
To: pgsql-jdbc
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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: newbie question to setTimestamp( int parameterIndex, Timestamp x, Calendar cal)
2005-07-19 10:49 newbie question to setTimestamp( int parameterIndex, Timestamp x, Calendar cal) Peter.Zoche@materna.de
@ 2005-07-19 11:00 ` Dave Cramer <pg@fastcrypt.com>
2005-07-19 11:25 ` Re: newbie question to setTimestamp( int parameterIndex, Timestamp x, Calendar cal) im i <linimi@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Dave Cramer @ 2005-07-19 11:00 UTC (permalink / raw)
To: Peter.Zoche@materna.de; +Cc: pgsql-jdbc
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
>
>
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: newbie question to setTimestamp( int parameterIndex, Timestamp x, Calendar cal)
2005-07-19 10:49 newbie question to setTimestamp( int parameterIndex, Timestamp x, Calendar cal) Peter.Zoche@materna.de
2005-07-19 11:00 ` Re: newbie question to setTimestamp( int parameterIndex, Timestamp x, Calendar cal) Dave Cramer <pg@fastcrypt.com>
@ 2005-07-19 11:25 ` im i <linimi@gmail.com>
0 siblings, 0 replies; 4+ messages in thread
From: im i @ 2005-07-19 11:25 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: Peter.Zoche@materna.de; pgsql-jdbc
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
>
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: newbie question to setTimestamp( int parameterIndex, T
@ 2005-07-19 11:06 Peter.Zoche@materna.de
0 siblings, 0 replies; 4+ messages in thread
From: Peter.Zoche@materna.de @ 2005-07-19 11:06 UTC (permalink / raw)
To: pgsql-jdbc
But I have stored my date and time information in a Calendar. Do
I have to construct a Timestamp from it and then use
setTimestamp( int index, Timestamp x) without the Calendar
parameter? What about my timezone?
-----Ursprüngliche Nachricht-----
Von: Dave Cramer [mailto:pg@fastcrypt.com]
Gesendet: Dienstag, 19. Juli 2005 13:00
An: Peter.Zoche@materna.de
Cc: pgsql-jdbc@postgresql.org
Betreff: Re: [JDBC] newbie question to setTimestamp( int parameterIndex,
Timestamp x, Calendar cal)
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
>
>
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2005-07-19 11:25 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-07-19 10:49 newbie question to setTimestamp( int parameterIndex, Timestamp x, Calendar cal) Peter.Zoche@materna.de
2005-07-19 11:00 ` Dave Cramer <pg@fastcrypt.com>
2005-07-19 11:25 ` im i <linimi@gmail.com>
2005-07-19 11:06 Re: newbie question to setTimestamp( int parameterIndex, T Peter.Zoche@materna.de
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