Re: sequences in JDBC - Mailing list pgsql-jdbc

From Dave Harkness
Subject Re: sequences in JDBC
Date
Msg-id 5.1.0.14.2.20010926142226.00b1f7d0@mail.meconomy.com
Whole thread Raw
In response to sequences in JDBC  ("Nick Fankhauser" <nickf@ontko.com>)
Responses Re: sequences in JDBC
List pgsql-jdbc
At 01:47 PM 9/26/2001, Nick Fankhauser wrote:
>I'm trying to use a sequence via JDBC, but I'm having a problem.
>
>The prepared statement I'm using looks like this:
>
>final String address_lineInsert = "insert into address_line( address_id,
>address_line_id, address_line_text) values (?,?,?)";

The problem is that it is treating "nextval..." as a literal string and
then trying to convert it to a number (as that is the column's type). You
need to change it to this:

final String address_lineInsert = "insert into address_line( address_id,
address_line_id, address_line_text) values (?, nextval('address_id_seq'), ?)";

This way Postgres will execute the nextval function as you wanted.

Peace,
Dave


pgsql-jdbc by date:

Previous
From: Russ McBride
Date:
Subject: connection error
Next
From: "Nick Fankhauser"
Date:
Subject: Re: sequences in JDBC