如何用java创建触发器

Python047

如何用java创建触发器,第1张

java是应用程序,可以通过jdbc接口调用触发器

create or replace trigger bj_customer

before update on customer

for each row

begin

update order set

cu_no=:new.cu_no,

cu_name=:new.cu_name,

cu_address=:new.cu_addess,

where cu_no=:old.cu_no;

end

调用executeUpdate方法即可

Trigger不是java特性也不是java内置的代码,而是其它程序的封装。

在Quartz中Trigger是触发器,Quartz中的触发器用来告诉调度程序作业什么时候触发

即Trigger对象是用来触发执行Job的

2.在Java程序里创建触发器

String sql=+" CREATE TRIGGER catefiles_trigger AFTER INSERT ON catefiles FOR EACH ROW"

+" begin"

+" declare scannum int"

+" set scannum = (select num from est_client_catescan_status where"

+" cateid=new.cateId and taskid=new.taskId and clientid=new.clientId)"

+" if(scannum>=0) then"

+" update catescan_status set num=scannum+1 where cateid=new.cateId and taskid=new.taskId and clientid=new.clientId"

+" else"

+" insert catescan_status(cateid,num,status,taskid,clientid) values(new.cateId,1,0,new.taskid,new.clientId)"

+" end if"

+" end"

Connection con = DbConnectionManager.getConnection()

PreparedStatement pstmt = con.prepareStatement(sql)

pstmt.execute()