我已通过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错误:SQLCODE = -204,SQLSTATE = 42704"
创建普通表并以此方式插入不会导致错误。我需要配置什么吗?
答案 0 :(得分:3)
您必须将临时表称为在架构会话中。尝试插入如下:
String insert = "INSERT INTO session.temporary_table (RECORD) VALUES (1)";
声明表时会隐式会话,但为了清楚起见,我通常将其声明为:
declare global temporary table session.temporary_table (...