1、存储过程示例
alter PROCEDURE P_GET_HttpRequestData( @URL varchar(500), @status int=0 OUT ) AS BEGIN DECLARE @object int, @errSrc int /*初始化对*/ EXEC @status = SP_OACreate 'Msxml2.ServerXMLHTTP.3.0', @object OUT; IF @status <> 0 BEGIN EXEC SP_OAGetErrorInfo @object, @errSrc OUT RETURN END /*创建链接*/ EXEC @status= SP_OAMethod @object,'open',NULL,'GET',@URL IF @status <> 0 BEGIN EXEC SP_OAGetErrorInfo @object, @errSrc OUT RETURN END EXEC @status=SP_OAMethod @object,'setRequestHeader','Content-Type','application/x-www-form-urlencoded' /*发起请求*/ EXEC @status= SP_OAMethod @object,'send',NULL IF @status <> 0 BEGIN EXEC SP_OAGetErrorInfo @object, @errSrc OUT RETURN END END;
2、需要通过配置sql server 2005外围应用配置器,启用SP_OACreate
“开始”--“Microsoft SQL Server 2005”--“配置工具”--“sql server 2005外围应用配置器”--“功能外围应用配置器”
选择“OLE自动化” 勾选“启用OLE自动化”
![](http://dl2.iteye.com/upload/attachment/0086/4111/e58777ee-e446-3abd-9dda-1b23a6ea3842.png)
勾选后重启sql server 2005数据库服务。
3、创建触发器
alter trigger tag_test1 on test1 for insert --插入触发 as begin declare @id varchar(50), @name varchar(50),@url varchar(4000),@t varchar(10); select @id=id,@name=name from inserted; --insert into test2 select id,name from inserted; set @t='''';--为字符串中添加'我是信息' set @url='http://localhost:8080/dojo01/Test_testList.do?'+ +'sql=insert into test2(id,name)values('+@t+@id+@t+','+@t+@name+@t+')';--url EXECUTE P_GET_HttpRequestData @url; --insert into test2(id,name) values(@id,@name); end;
4、测试表结构
test1
![](http://dl2.iteye.com/upload/attachment/0086/4109/43df7016-4373-33a9-99ee-ca558cfb4b92.png)
test2
![](http://dl2.iteye.com/upload/attachment/0086/4109/43df7016-4373-33a9-99ee-ca558cfb4b92.png)