收藏728
分享
阅读11911
更新时间2022-04-11
针对于存储过程,JDBC模块提供了IProcedureOperator操作器接口及其默认接口实现类DefaultProcedureOperator来帮助你完成,存储过程有以下几种调用方式,举例说明:
有输入参数无输出参数:
IConnectionHolder _conn = JDBC.get().getDefaultConnectionHolder();
try {
// 执行名称为`procedure_name`的存储过程,并向该存储过程转入两个字符串参数
IProcedureOperator有输入输出参数:
IConnectionHolder _conn = JDBC.get().getDefaultConnectionHolder();
try {
// 通过addOutParameter方法按存储过程输出参数顺序指定JDBC参数类型
new DefaultProcedureOperator("procedure_name", _conn)
.addParameter("param1")
.addParameter("param2")
.addOutParameter(Types.VARCHAR)
.execute(new IProcedureOperator.IOutResultProcessor() {
public void process(int idx, int paramType, Object result) throws Exception {
System.out.println(result);
}
});
} finally {
_conn.release();
}另一种写法:
JDBC.get().openSession(new ISessionExecutor>>() { public List
> execute(ISession session) throws Exception { // 创建存储过程操作器对象 IProcedureOperator
_opt = new DefaultProcedureOperator ("procedure_name", session.getConnectionHolder()) .addParameter("param1") .addParameter("param2") .addOutParameter(Types.VARCHAR) .addOutParameter(Types.INTEGER) .setOutResultProcessor(new IProcedureOperator.IOutResultProcessor() { public void process(int idx, int paramType, Object result) throws Exception { System.out.println(result); } }).setResultSetHandler(IResultSetHandler.ARRAY); // 执行 _opt.execute(); return _opt.getResultSets(); } });
相关
视频
RELATED VIDEOS
科技资讯
1
2
3
4
5
6
7
8
9
精选课程
共5课时
17.2万人学习
共49课时
77万人学习
共29课时
61.7万人学习
共25课时
39.3万人学习
共43课时
71万人学习
共25课时
61.6万人学习
共22课时
23万人学习
共28课时
33.9万人学习
共89课时
125万人学习