Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How do SQLServer triggers call JavaWeb interface

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "SQLServer trigger how to call JavaWeb interface", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "SQLServer trigger how to call JavaWeb interface" this article.

In the past few days, I received a requirement that I needed to synchronize the databases of different systems. I needed to make an intermediate platform to connect. I immediately thought of the trigger calling the interface and then passing it through API and then writing to another database.

SqlServer trigger calls JavaWeb interface

1. Enable Ole Automation Procedures

If sqlServer wants to call the web interface, it needs to use its own stored procedure. These stored procedures are turned off by default after version 2005, so they should be opened first.

Sp_configure 'show advanced options', 1 / GORECONFIGURE / GOSPP configure' Ole Automation Procedures', 1 / GORECONFIGURE / GOEXEC sp_configure 'Ole Automation Procedures';GO

Close Ole Automation Procedures

Sp_configure 'show advanced options', 1 / GORECONFIGURE / GOSPP configure' Ole Automation Procedures', 1 / GORECONFIGURE / GOEXEC sp_configure 'Ole Automation Procedures';GO

Turn off advanced options

Sp_configure 'show advanced options', 0 and GORECONFIGUREX go

Then you can write the trigger, because there are more contents on my side of the table, so just look at the code.

CREATE TRIGGER [dbo]. [kingdee] ON [dbo]. [weighing information] WITH EXECUTE AS CALLERFOR INSERTASBEGIN-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 serial number from inserted); SELECT @ carid = (select car number from inserted); SELECT @ type = (select weighing type from inserted); SELECT @ sendplace = (select shipping unit from inserted); SELECT @ consignee = (select receiving unit from inserted); SELECT @ material = (select name from inserted) SELECT @ specification = (select specification from inserted); SELECT @ gw = (select gross weight from inserted); SELECT @ tare = (select tare weight from inserted); SELECT @ nw = (select net weight from inserted); SELECT @ kw = (select buckle weight from inserted); SELECT @ aw = (select real weight from inserted); SELECT @ price = (select unit price from inserted) SELECT @ money = (select amount from inserted); SELECT @ zfxs = (select fold coefficient from inserted); SELECT @ square = (select square from inserted); SELECT @ weighingcost = (select weight from inserted); SELECT @ gwtime = (select gross weight time from inserted); SELECT @ taretime = (select tare weight time 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 ENDGOEXEC sp_addextendedproperty'MS_Description', N' Flip-flop after insertion of weighing information table', 'SCHEMA', weighing information', 'TRIGGER', weighing information'

It looks complicated, but it's not complicated at all, because the table in this database is in Chinese (I can't change it in Chinese not in the table system I built), it basically takes the inserted data and triggers, requests, and then API executes to insert another database.

Then execute the insert statement to see the result of the execution.

The above is all the contents of the article "how SQLServer triggers call the JavaWeb interface". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report