2016-04-02 122 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 (...