「java创建触发器」java实现触发器
今天给各位分享java创建触发器的知识,其中也会对java实现触发器进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、java中怎么创建mysql的触发器
- 2、java里trigger是干什么用的?
- 3、关于mysql中的触发器能调用JAVA吗的搜索推荐
- 4、JAVA用代码操作数据库创建表,视图,触发器,存储过程等。
- 5、如何用java创建触发器
- 6、java如何调用MySQL的触发器
java中怎么创建mysql的触发器
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();
java里trigger是干什么用的?
Trigger不是java特性也不是java内置的代码,而是其它程序的封装。
在Quartz中Trigger是触发器,Quartz中的触发器用来告诉调度程序作业什么时候触发
即Trigger对象是用来触发执行Job的
关于mysql中的触发器能调用JAVA吗的搜索推荐
肯定不可以,mysql不能调用java代码,但是可以在java中创建触发器
1.使用SQL创建触发器
DELIMITER $$CREATE TRIGGER `catefiles_trigger` AFTER INSERT ON `catefiles` FOR EACH ROWbegin
declare num1 int; set num1 = (select num from est_client_catescan_status where cateid=new.cateId and taskid=new.taskId and clientid=new.clientId); if(num1=0) then update catescan_status set num=num1+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$$
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();
3.可以看出区别:在java中创建触发器,不需要限定符DELIMITER ,加上的话执行过程中会报MySQL语法错误
JAVA用代码操作数据库创建表,视图,触发器,存储过程等。
create
or
replace
trigger
trg_delete_count
before
delete
on
student
for
each
row
begin
delete
from
成绩表
where
成绩表.学号=:old.学号;
commit;
end;
想要实现类似的功能,不一定要用触发器的,可以设置两个表的主键和外键,设置级联删除关系,删除主键时,外键表中的记录也会自动删除。
如何用java创建触发器
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方法即可
java如何调用MySQL的触发器
触发器顾名思意就是在某个动作执行时自动触发执行的,不用调用,比如你是在add和delete数据时加触发器,只要你定义的对,数据库在向你指定的那张表add和delete数据时,该触发器就会自动触发
java创建触发器的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java实现触发器、java创建触发器的信息别忘了在本站进行查找喔。
发布于:2022-12-01,除非注明,否则均为
原创文章,转载请注明出处。