2016-04-02 3 views
0

を挿入することができません:は、私は、JDBC経由で私の新しいDB2データベースに接続しており、一時テーブルを作成し、挿入しようとしている一時テーブルに

String createTemporaryTable = "declare global temporary table temporary_table (RECORD smallint) ON COMMIT PRESERVE ROWS in TEMPTABLESPACE"; 
statement.execute(createTemporaryTable); 

String insert = "INSERT INTO temporary_table (RECORD) VALUES (1)"; 

statement.execute(insert); 
connection.commit(); 

これは

"DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704"

の作成につながります通常の表とこの方法を挿入するとエラーは発生しません。設定が必要なことはありますか?

答えて

3

一時テーブルをスキーマセッション中に参照する必要があります。

String insert = "INSERT INTO session.temporary_table (RECORD) VALUES (1)"; 

テーブルを宣言するときに、セッションは暗黙的であるが、明確にするため、私は通常のようにそれを宣言:

declare global temporary table session.temporary_table (... 
のように挿入してみてください