Java 创建触发器失败

触发器代码如下

1
2
3
4
5
6
7
8
9
10
11
12
create or replace trigger trigger_33zOtisNB5cZ_LMAhwtmDg
before insert or update of STUNAME
on T_STU for each row
begin
if inserting then
insert into table_33zOtisNB5cZ_LMAhwtmDg values ('insert',sysdate,:new.STUID);
elsif updating then
insert into table_33zOtisNB5cZ_LMAhwtmDg values ('update',sysdate,:new.STUID);
elsif deleting then
insert into table_33zOtisNB5cZ_LMAhwtmDg values ('delete',sysdate,:old.STUID);
end if;
end;

java执行代码

1
2
PreparedStatement state = conn.prepareCall(sql);
state.execute();

执行时出错 Missing IN or OUT parameter at index:: 1

猜测原因:执行的时候将上述语句翻译成了带参数的查询,如果把创建触发器语句中的 :new,:old 等关键字去掉则执行成功

解决方案:

1
2
Statement state = conn.createStatement();
state.execute(sql);

Done!

查看评论