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();