oracle通过存储过程调用web接口
2019-07-28 本文已影响0人
御情守剑
sql语句
create or replace procedure Test(userName in varchar2,password in VARCHAR2,
flag out varchar2) is
req utl_http.req;
resp utl_http.resp;
-------用户权限接口调用
valueStr varchar2(1024);
begin
req := utl_http.begin_request('http://localhost:8080/test/test?userName='||userName||'&&password='||password||'');
utl_http.set_header(req, 'User-Agent', 'Mozilla/4.0');
resp := utl_http.get_response(req);
utl_http.read_line(resp, valueStr, true);
flag := valueStr;
utl_http.end_response(resp);
end Test;
配置acl权限(oracle11及以上访问网络,账号需要acl权限)
BEGIN
DBMS_NETWORK_ACL_ADMIN.CREATE_ACL (
acl => 'Test.xml',
description => 'Test',
principal => 'yqsj',
is_grant => TRUE,
privilege => 'connect');
END;
BEGIN
DBMS_NETWORK_ACL_ADMIN.assign_acl (
acl => 'Test.xml',
host => 'localhost', ---SMTP服务器地址
lower_port => 25,
upper_port => 9090);
COMMIT;
END;
java调用存储过程,以及接受结果
Configuration cfg = new Configuration().configure();
SessionFactory sessionFactory = cfg.buildSessionFactory();
Session session = sessionFactory.openSession(); //获取hibernate会话
try{
CallableStatement statement = session.connection().prepareCall(
"{call Test(?,?,?)}");
statement.setString("userName", userName);
statement.setString("password", password);
statement.registerOutParameter("flag", OracleTypes.VARCHAR);
statement.executeUpdate();
String keycode = statement.getString("flag");
session.close();
}catch (Exception e) {
e.printStackTrace();
}