SQLServer触发器调用JavaWeb接口
2021/12/31 8:07:32
本文主要是介绍SQLServer触发器调用JavaWeb接口,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
这几天接到一个需求需要吧不同系统的数据库进行同步,需要我做一个中间平台进行连接,瞬间就想到了触发器调用接口然后通过API进行传递再写入另一个数据库。
sqlServer触发器调用JavaWeb接口
1、开启 Ole Automation Procedures
sqlServer要想调用web接口,就要使用自带的存储过程。而这些存储过程2005版本以后默认时关闭的,所以要先开启。
sp_configure 'show advanced options', 1; GO RECONFIGURE; GO sp_configure 'Ole Automation Procedures', 1; GO RECONFIGURE; GO EXEC sp_configure 'Ole Automation Procedures'; GO
关闭 Ole Automation Procedures
sp_configure 'show advanced options', 1; GO RECONFIGURE; GO sp_configure 'Ole Automation Procedures', 1; GO RECONFIGURE; GO EXEC sp_configure 'Ole Automation Procedures'; GO
关闭高级选项
sp_configure 'show advanced options', 0; GO RECONFIGURE; GO
然后就可以进行写触发器,因为我这边表的内容比较多,大家直接看代码就好了。
CREATE TRIGGER [dbo].[kingdee] ON [dbo].[称重信息] WITH EXECUTE AS CALLER FOR INSERT AS BEGIN -- Type the SQL Here. DECLARE @fbillno int; DECLARE @carid varchar(4000); DECLARE @type varchar(4000); DECLARE @sendplace varchar(4000); DECLARE @consignee varchar(4000); DECLARE @material varchar(4000); DECLARE @specification varchar(4000); DECLARE @gw varchar(4000); DECLARE @tare varchar(4000); DECLARE @nw varchar(4000); DECLARE @kw varchar(4000); DECLARE @aw varchar(4000); DECLARE @price varchar(4000); DECLARE @money varchar(4000); DECLARE @zfxs varchar(4000); DECLARE @square varchar(4000); DECLARE @weighingcost varchar(4000); DECLARE @gwtime varchar(4000); DECLARE @taretime varchar(4000); declare @url varchar(4000); declare @object int; declare @responseText varchar(4000); SELECT @fbillno = (select 流水号 from inserted); SELECT @carid = (select 车号 from inserted); SELECT @type = (select 过磅类型 from inserted); SELECT @sendplace = (select 发货单位 from inserted); SELECT @consignee = (select 收货单位 from inserted); SELECT @material = (select 货名 from inserted); SELECT @specification = (select 规格 from inserted); SELECT @gw = (select 毛重 from inserted); SELECT @tare = (select 皮重 from inserted); SELECT @nw = (select 净重 from inserted); SELECT @kw = (select 扣重 from inserted); SELECT @aw = (select 实重 from inserted); SELECT @price = (select 单价 from inserted); SELECT @money = (select 金额 from inserted); SELECT @zfxs = (select 折方系数 from inserted); SELECT @square = (select 方量 from inserted); SELECT @weighingcost = (select 过磅费 from inserted); SELECT @gwtime = (select 毛重时间 from inserted); SELECT @taretime = (select 皮重时间 from inserted); SELECT @url = 'http://ip/saveweight/' + CONVERT(INT, @fbillno)+'/'+ CONVERT(VARCHAR, @carid) +'/'+ CONVERT(VARCHAR, @type)+'/'+ CONVERT(VARCHAR, @sendplace)+'/'+ CONVERT(VARCHAR, @consignee)+'/'+ CONVERT(VARCHAR, @material) +'/'+ CONVERT(VARCHAR, @specification)+'/'+ CONVERT(VARCHAR, @gw)+'/'+ CONVERT(VARCHAR, @tare)+'/'+ CONVERT(VARCHAR, @nw) +'/'+ CONVERT(VARCHAR, @kw)+'/'+ CONVERT(VARCHAR, @aw)+'/'+ CONVERT(VARCHAR, @price)+'/'+ CONVERT(VARCHAR, @money) +'/'+ CONVERT(VARCHAR, @zfxs)+'/'+ CONVERT(VARCHAR, @square)+'/'+ CONVERT(VARCHAR, @weighingcost)+'/'+ CONVERT(VARCHAR, @gwtime) +'/'+ CONVERT(VARCHAR, @taretime); print @url; -- insert into one (id, name) VALUES (@id, @url); exec sp_OACreate'MSXML2.XMLHTTP',@object out exec sp_OAMethod @object,'open',null,'get',@url,'false' exec sp_OAMethod @object,'send' exec sp_OAMethod @object,'responseText',@responseText output print @responseText exec sp_OADestroy @object SET NOCOUNT ON; END GO EXEC sp_addextendedproperty 'MS_Description', N'称重信息表插入后触发器', 'SCHEMA', N'dbo', 'TABLE', N'称重信息', 'TRIGGER', N'kingdee'
看着复杂其实一点也不复杂,因为这个数据库的表是中文(不是我建的表系统中的中文的我没办法改),大致就是获取插入的数据然后进行触发,请求,然后API执行插入另一个数据库。
然后执行插入语句就可以看到执行的结果了~
这篇关于SQLServer触发器调用JavaWeb接口的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-24怎么修改Kafka的JVM参数?-icode9专业技术文章分享
- 2024-12-23线下车企门店如何实现线上线下融合?
- 2024-12-23鸿蒙Next ArkTS编程规范总结
- 2024-12-23物流团队冬至高效运转,哪款办公软件可助力风险评估?
- 2024-12-23优化库存,提升效率:医药企业如何借助看板软件实现仓库智能化
- 2024-12-23项目管理零负担!轻量化看板工具如何助力团队协作
- 2024-12-23电商活动复盘,为何是团队成长的核心环节?
- 2024-12-23鸿蒙Next ArkTS高性能编程实战
- 2024-12-23数据驱动:电商复盘从基础到进阶!
- 2024-12-23从数据到客户:跨境电商如何通过销售跟踪工具提升营销精准度?