Skip site navigation (1) Skip section navigation (2)

Updateable ResultSet doesn't fetch sequence-generated values

From: Clemens Eisserer <linuxhippy(at)gmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Updateable ResultSet doesn't fetch sequence-generated values
Date: 2009-07-26 20:10:05
Message-ID: 194f62550907261310v740cd3f9p8a98fa0a81fcf4f7@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-jdbc
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

Responses

pgsql-jdbc by date

Next:From: Clemens EissererDate: 2009-07-26 20:12:03
Subject: Re: [GENERAL] Implicit sequence with start value?
Previous:From: Scott MarloweDate: 2009-07-26 17:34:24
Subject: Re: Implicit sequence with start value?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group