[pgsql-jp: 27161] 更新可能ResultSetによるデータの追加

Susumu Nagamatsu naga2010 @ mbi.nifty.com
2002年 8月 27日 (火) 00:40:03 JST


初めて投稿させていただきます。nagamastuと申します。
javaの話しが主になってしまいますが、postgreSQLを使っての話題であればよろしいでしょうか?
問題あればご指摘下さい。

以下のように更新可能ResultSetによりデータベースへデータ追加しようとするとどうしてもエラーになります。
DB環境: postgreSQL7.2.1 JDBCドライバ(postgreSQL7.2用)RED HAT LINUX7.3
開発環境 jdk1.4.0_01-b03  JBUILDER6ENT WIN2K

statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
resultset = statement.executeQuery("select * from test1");
※test1は、create table test1 (id1 integer primary key not null, id2 integer not null);で作成しました。
 データは3件登録済みの状態。
resultset.moveToInsertRow();
resultset.updateInt("id2", 9999);
resultset.insertRow();
resultset.moveToCurrentRow();

これを実行するとresultset.moveToInsertRow();でエラーになり下記のメッセージがでます。

Result Set not updateable. The query that generated this result set must select only one table, 
and must select all primary keys from that table. See the JDBC 2.1 API Specification, 
section 5.6 for more details.

しかし同じ条件でupdateRow(), deleteRow()はうまく行きます。
(jdk1.3.1でも試しましたが同じ結果でした)
ちなみにJDBC 2.1 API Specification, section 5.6 を見ると、

Developers can, however, generally expect queries which meet
the following criteria to produce an updatable result set:
1. The query references only a single table in the database.
2. The query does not contain any join operations.
3. The query selects the primary key of the table it references.
In addition, an SQL query should also satisfy the conditions listed below if inserts are
to be performed.
4. The query selects all of the non-nullable columns in the underlying table.
5. The query selects all columns that don’t have a default value.

とありますが全て条件を満たしているつもりです。

長文申し訳ありませんが、どなたかアドバイスのほどお願い致します。

以上
--




pgsql-jp メーリングリストの案内