RE: jdbc how to get SERIAL

From: Peter Mount <petermount(at)it(dot)maidstone(dot)gov(dot)uk>
To: "'Joseph Shraibman'" <jks(at)selectacast(dot)net>, Wim Ceulemans <Wim(dot)Ceulemans(at)nice(dot)be>
Cc: John Thorhauer <jthorhauer(at)phoenixcolor(dot)com>, pgsql-interfaces(at)postgresql(dot)org
Subject: RE: jdbc how to get SERIAL
Date: 2000-07-19 07:00:30
Message-ID: 1B3D5E532D18D311861A00600865478CF1B0F6@exchange1.nt.maidstone.gov.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)selectacast(dot)net]
Sent: Tuesday, July 18, 2000 10:16 PM
To: Wim Ceulemans
Cc: John Thorhauer; pgsql-interfaces(at)postgresql(dot)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.

Browse pgsql-interfaces by date

  From Date Subject
Next Message Peter Mount 2000-07-19 07:05:15 RE: Clob or Blob in JDBC -> ImageViewer
Previous Message Peter Mount 2000-07-19 06:59:03 RE: Searching Blobs