pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Clemens Eisserer <linuxhippy@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: Updateable ResultSet doesn't fetch sequence-generated values
Date: Sun, 26 Jul 2009 16:10:05 -0400
Message-ID: <194f62550907261310v740cd3f9p8a98fa0a81fcf4f7@mail.gmail.com> (raw)

Hello,

I am using a library which is using the JDBCRowSet API, in order to
bind a user-interface with a SQL database.
The library relies on auto generated primary keys (I am using
sequences for this task), however after inserting, the key-column with
the server-side generated value is set to 0.
I am porting the application from MySQL-5.0 to PostgreSQL-8.3, and
MySQL sets the key-column to the value generated by auto_increment.

Am I doing something wrong here, or is it a bug? Is that behaviour
specified at all?

The following code outputs "Hallo has key: 0" although it should
output "Hallo has key: 10000".

> CREATE TABLE customer (key SERIAL PRIMARY KEY NOT NULL, name VARCHAR(255));
> ALTER SEQUENCE customer_key_seq START WITH 10000;

> JdbcRowSet rowset = new JdbcRowSetImpl(instance.ssConnection.getConnection());
> rowset.setType(ResultSet.TYPE_SCROLL_INSENSITIVE);
> rowset.setConcurrency(ResultSet.CONCUR_UPDATABLE);
> rowset.setCommand("SELECT * FROM customer");
> rowset.execute();
> rowset.moveToInsertRow();
	
> rowset.updateString("name", "Hello");
> rowset.insertRow();	
> System.out.println(rowset.getString("name")+" has key: "+rowset.getInt("key"));

Thank you in advance, Clemens



view thread (3+ messages)  latest in thread

Message-ID: <194f62550907261310v740cd3f9p8a98fa0a81fcf4f7@mail.gmail.com>
Permalink:  ../194f62550907261310v740cd3f9p8a98fa0a81fcf4f7@mail.gmail.com/
Also on:    postgresql.org/message-id/194f62550907261310v740cd3f9p8a98fa0a81fcf4f7@mail.gmail.com

 · 

reply

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: linuxhippy@gmail.com
  Subject: Re: Updateable ResultSet doesn't fetch sequence-generated values
  In-Reply-To: <194f62550907261310v740cd3f9p8a98fa0a81fcf4f7@mail.gmail.com>
  References: <194f62550907261310v740cd3f9p8a98fa0a81fcf4f7@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