標籤:style blog http io ar color os 使用 sp
DB2內建了WebService用戶端的實現,具體命令如下:
啟用命令:
db2enable_soap_udf -n dbName -u uID -p password [-force]
The parameters have the following definitions:
dbName - The database name to be enabled
uID user - ID for accessing the database
password - The password associated with the user ID
-force - Attempts to drop any existing functions.
如:db2enable_soap_udf -n MS_TRD -u zjyw -p 123456
啟用成功後,可調用以下API介面:
db2xml.soaphttpv (VARCHAR(256), VARCHAR(256), VARCHAR(3072))
db2xml.soaphttpv (VARCHAR(256), VARCHAR(256), CLOB(1M))
db2xml.soaphttpc (VARCHAR(256), VARCHAR(256), varchar(3072))
db2xml.soaphttpc (VARCHAR(256), VARCHAR(256), CLOB(1M))
db2xml.soaphttpcl ( VARCHAR(256), VARCHAR(256), varchar(3072))
停用命令:
db2disable_soap_udf -n dbName -u uID -p password
調用步驟:
1、測試webService用戶端與服務端的連通性
建立test.sql,編寫如下代碼:
connect to MS_TRD;VALUES db2xml.soaphttpc(‘http://191.168.0.209:8080/SHCH/services/shch‘,‘http://191.168.0.209:8080/SHCH/services/shch.shchHttpEndpoint/‘,varchar (‘<SendMessage xmlns="http://axis2.shch.xtp.xquant.com"><action>81</action><requestXml>12345</requestXml></SendMessage>‘));
在DB2命令視窗中執行:db2 -tvf d:\test.sql
成功調用後,就可以繼續寫DB2函數供預存程序或者觸發器調用了
2、建立表TTRD_UDF,具體見使用 DB2 觸發器和Java UDF實現業務通知
3、新增10000條測試資料
begin atomic declare v_cnt int; set v_cnt=0; while (v_cnt<10000) do insert into TTRD_UDF(CODE, NAME, REMARK) values (rtrim(char(v_cnt+100000)),‘test‘, ‘-‘); set v_cnt=v_cnt+1; end while;end
4、建立DB2函數
CREATE FUNCTION zjyw.SENDMESSAGE2 (symbol VARCHAR(100))RETURNS VARCHAR(1000)LANGUAGE SQL CONTAINS SQLEXTERNAL ACTION NOT DETERMINISTICRETURNVALUES db2xml.soaphttpc(‘http://191.168.0.209:8080/SHCH/services/shch‘,‘http://191.168.0.209:8080/SHCH/services/shch.shchHttpEndpoint/‘,varchar (‘<SendMessage xmlns="http://axis2.shch.xtp.xquant.com"><action>81</action><requestXml>‘|| + symbol + ||‘</requestXml></SendMessage>‘ ) ) )
5、建立TTRD_UDF觸發器
CREATE TRIGGER ZJYW.AFTER_UPDATE_UFTAFTER UPDATE OF NAME ON ZJYW.TTRD_UDFREFERENCING OLD AS OLDROW NEW AS NEWROWFOR EACH ROW MODE DB2SQLBEGIN ATOMICIF(NEWROW.NAME<>‘‘)THENVALUES(SENDMESSAGE2(OLDROW.CODE));END IF;END;
6、測試批量修改10000條資料效能
update zjyw.TTRD_UDF set NAME=‘TEST2‘
全部執行完成耗時36分17秒,效能很一般。
如果WebService服務端未開啟時,觸發器會逾時等待,實用性比較差。
使用DB2內建的SOAP UDF實現業務通知