pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedjdbc how to get SERIAL
5+ messages / 3 participants
[nested] [flat]
* jdbc how to get SERIAL
@ 2000-07-18 18:36 John Thorhauer <jthorhauer@phoenixcolor.com>
0 siblings, 1 reply; 5+ messages in thread
From: John Thorhauer @ 2000-07-18 18:36 UTC (permalink / raw)
To: pgsql-interfaces
How do I get the id column of a row via jdbc if the column is a SERIAL
column. I want to get the id of the row after I insert new data via
jdbc execute command.
Thanks,
John Thorhauer
--
********************************
** John Thorhauer
** jthorhauer@phoenixcolor.com
********************************
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: jdbc how to get SERIAL
@ 2000-07-18 19:00 Joseph Shraibman <jks@selectacast.net>
parent: John Thorhauer <jthorhauer@phoenixcolor.com>
0 siblings, 1 reply; 5+ messages in thread
From: Joseph Shraibman @ 2000-07-18 19:00 UTC (permalink / raw)
To: John Thorhauer <jthorhauer@phoenixcolor.com>; +Cc: pgsql-interfaces
Explictly get the value.
For example:
ResultSet rs = st.executeQuery("select nextval('my_col_name_seq'));
st.next(); int id = st.getInt(1);
st.executeUpdate("insert into mytable values(id = "+id+" , myvalu =
'blah');");
John Thorhauer wrote:
>
> How do I get the id column of a row via jdbc if the column is a SERIAL
> column. I want to get the id of the row after I insert new data via
> jdbc execute command.
>
> Thanks,
> John Thorhauer
>
> --
> ********************************
> ** John Thorhauer
> ** jthorhauer@phoenixcolor.com
> ********************************
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: jdbc how to get SERIAL
@ 2000-07-18 21:15 Joseph Shraibman <jks@selectacast.net>
parent: Joseph Shraibman <jks@selectacast.net>
0 siblings, 0 replies; 5+ messages in thread
From: Joseph Shraibman @ 2000-07-18 21:15 UTC (permalink / raw)
To: Wim Ceulemans <Wim.Ceulemans@nice.be>; +Cc: John Thorhauer <jthorhauer@phoenixcolor.com>; pgsql-interfaces
Wim Ceulemans wrote:
>
> Joseph Shraibman wrote:
> >
> > Explictly get the value.
> >
> > For example:
> > ResultSet rs = st.executeQuery("select nextval('my_col_name_seq'));
> > st.next(); int id = st.getInt(1);
> > st.executeUpdate("insert into mytable values(id = "+id+" , myvalu =
> > 'blah');");
> >
> > John Thorhauer wrote:
> > >
> > > How do I get the id column of a row via jdbc if the column is a SERIAL
> > > column. I want to get the id of the row after I insert new data via
> > > jdbc execute command.
> > >
> > > Thanks,
> > > John Thorhauer
> > >
>
> Doesn't it have to be currval in stead of nextval?
>
No, you want to do an insert, to you need to get the nextval.
^ permalink raw reply [nested|flat] 5+ messages in thread
* RE: jdbc how to get SERIAL
@ 2000-07-19 06:41 Peter Mount <petermount@it.maidstone.gov.uk>
0 siblings, 0 replies; 5+ messages in thread
From: Peter Mount @ 2000-07-19 06:41 UTC (permalink / raw)
To: 'John Thorhauer' <jthorhauer@phoenixcolor.com>; pgsql-interfaces
The function currval does this. Ie:
select currval("mycol_id_seq");
where mycol is the table and id is the column for the sequence.
Would return that value. PS: The result is for that session, so if another
session increments that sequence, you don't see that value but the last
value of _your_ session.
Peter
--
Peter Mount
Enterprise Support
Maidstone Borough Council
Any views stated are my own, and not those of Maidstone Borough Council
-----Original Message-----
From: John Thorhauer [mailto:jthorhauer@phoenixcolor.com]
Sent: Tuesday, July 18, 2000 7:37 PM
To: pgsql-interfaces@postgresql.org
Subject: [INTERFACES] jdbc how to get SERIAL
How do I get the id column of a row via jdbc if the column is a SERIAL
column. I want to get the id of the row after I insert new data via
jdbc execute command.
Thanks,
John Thorhauer
--
********************************
** John Thorhauer
** jthorhauer@phoenixcolor.com
********************************
^ permalink raw reply [nested|flat] 5+ messages in thread
* RE: jdbc how to get SERIAL
@ 2000-07-19 07:00 Peter Mount <petermount@it.maidstone.gov.uk>
0 siblings, 0 replies; 5+ messages in thread
From: Peter Mount @ 2000-07-19 07:00 UTC (permalink / raw)
To: 'Joseph Shraibman' <jks@selectacast.net>; Wim Ceulemans <Wim.Ceulemans@nice.be>; +Cc: John Thorhauer <jthorhauer@phoenixcolor.com>; pgsql-interfaces
If you call nextval() then ther sequence will increment. Once the insert has
been done, currval() will then return the last value used in that
connection. You don't have any race conditions with other connections with
currval.
Peter
--
Peter Mount
Enterprise Support
Maidstone Borough Council
Any views stated are my own, and not those of Maidstone Borough Council
-----Original Message-----
From: Joseph Shraibman [mailto:jks@selectacast.net]
Sent: Tuesday, July 18, 2000 10:16 PM
To: Wim Ceulemans
Cc: John Thorhauer; pgsql-interfaces@postgresql.org
Subject: Re: [INTERFACES] jdbc how to get SERIAL
Wim Ceulemans wrote:
>
> Joseph Shraibman wrote:
> >
> > Explictly get the value.
> >
> > For example:
> > ResultSet rs = st.executeQuery("select nextval('my_col_name_seq'));
> > st.next(); int id = st.getInt(1);
> > st.executeUpdate("insert into mytable values(id = "+id+" ,
myvalu =
> > 'blah');");
> >
> > John Thorhauer wrote:
> > >
> > > How do I get the id column of a row via jdbc if the column is a SERIAL
> > > column. I want to get the id of the row after I insert new data via
> > > jdbc execute command.
> > >
> > > Thanks,
> > > John Thorhauer
> > >
>
> Doesn't it have to be currval in stead of nextval?
>
No, you want to do an insert, to you need to get the nextval.
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2000-07-19 07:00 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-07-18 18:36 jdbc how to get SERIAL John Thorhauer <jthorhauer@phoenixcolor.com>
2000-07-18 19:00 ` Joseph Shraibman <jks@selectacast.net>
2000-07-18 21:15 ` Joseph Shraibman <jks@selectacast.net>
2000-07-19 06:41 RE: jdbc how to get SERIAL Peter Mount <petermount@it.maidstone.gov.uk>
2000-07-19 07:00 RE: jdbc how to get SERIAL Peter Mount <petermount@it.maidstone.gov.uk>
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