ADF中调用PLSQL存储过程和函数
2011-03-17 22:51
405 查看
下面是从
ADF
guide
中总结的一段调用
PLSQL
存储过程和函数的方法,仅供参考。
1
,调用没有参数的存储过程
可以使用
executeCommand
()
函数,在
AM
的实现类中可以这样来使用:
getDBTransaction().executeCommand("begin
devguidepkg.proc_with_no_args; end;");
2
,调用只有输入参数的存储过程
可以使用
getDBTransaction
提供的
createPreparedStatement
来创建
PreparedStatement
对象,使用示例:
getDBTransaction().createPreparedStatement("begin
"+stmt+";end;",0);
3
,调用只有输入参数的存储函数
可以使用
getDBTransaction
提供的
createCallableStatement
来创建
CallableStatement
对象,使用示例:
getDBTransaction().createCallableStatement("begin
? := "+stmt+";end;",0);
4
,其他情况
调用既有输入参数又有输出参数的存储过程或函数可以使用
CallableStatement
,使用方法和
3
相同。
5
,调用存储过程
操作流程:
1)
创建PreparedStatement
2)
设置输入输出参数
3)
执行查询
4)
关闭语句链接
5
,注意点:
1)
数据库连接占用数据库资源,务必在finally
语句中关闭数据库连接。
2)
对于在执行过程中发生的错误要throw
出来,否则会增加调试时寻找异常(错误)的难度。
3)
执行查询方法execute, executeQuery, executeUpdate
的区别:
executeUpdate
用于执行带有INSERT/UPDATE/DELETE
操作的语句
executeQuery
用于执行带有查询操作的语句
execute
用于执行任意类型的SQL
语句
ADF
guide
中总结的一段调用
PLSQL
存储过程和函数的方法,仅供参考。
1
,调用没有参数的存储过程
可以使用
executeCommand
()
函数,在
AM
的实现类中可以这样来使用:
getDBTransaction().executeCommand("begin
devguidepkg.proc_with_no_args; end;");
2
,调用只有输入参数的存储过程
可以使用
getDBTransaction
提供的
createPreparedStatement
来创建
PreparedStatement
对象,使用示例:
getDBTransaction().createPreparedStatement("begin
"+stmt+";end;",0);
3
,调用只有输入参数的存储函数
可以使用
getDBTransaction
提供的
createCallableStatement
来创建
CallableStatement
对象,使用示例:
getDBTransaction().createCallableStatement("begin
? := "+stmt+";end;",0);
4
,其他情况
调用既有输入参数又有输出参数的存储过程或函数可以使用
CallableStatement
,使用方法和
3
相同。
5
,调用存储过程
操作流程:
1)
创建PreparedStatement
2)
设置输入输出参数
3)
执行查询
4)
关闭语句链接
void callStoredProcedure(String stmt, Object[] bindVars) { PreparedStatement st = null; try { // 1. Create a JDBC PreparedStatement for st = getDBTransaction().createPreparedStatement("begin "+stmt+";end;",0); if (bindVars != null) { // 2. Loop over values for the bind variables passed in, if any for (int z = 0; z < bindVars.length; z++) { // 3. Set the value of each bind variable in the statement st.setObject(z + 1, bindVars[z]); } } // 4. Execute the statement st.executeUpdate(); } catch (SQLException e) { throw new JboException(e); } finally { if (st != null) { try { // 5. Close the statement st.close(); } catch (SQLException e) {} } } }
5
,注意点:
1)
数据库连接占用数据库资源,务必在finally
语句中关闭数据库连接。
2)
对于在执行过程中发生的错误要throw
出来,否则会增加调试时寻找异常(错误)的难度。
3)
执行查询方法execute, executeQuery, executeUpdate
的区别:
executeUpdate
用于执行带有INSERT/UPDATE/DELETE
操作的语句
executeQuery
用于执行带有查询操作的语句
execute
用于执行任意类型的SQL
语句
相关文章推荐
- ADF中调用PLSQL存储过程和函数
- ADF中调用PLSQL存储过程和函数
- Oracle分页存储过程及PLSQL中的调用脚本
- Day60-Oracle04 - PLSQL编程、游标cursor、例外exception、存储过程(procedure)、存储函数(function)、java调用存储过程、触发器(trigger)
- java中调用数据库中的存储过程和函数
- php调用mysql存储过程和函数的方法
- 存储过程调用自定义函数实现循环更新
- php调用mysql存储过程和函数的方法
- Oracle分页存储过程及PLSQL中的调用脚本
- MySQL存储过程和自定义函数、Navicat、创建存储过程和函数、调用存储过程和函数、三种方式、In和Out类型参数、
- Oracle 创建存储过程以及PlSql 调用 存储过程
- plsql-shell调用存储过程
- php调用mysql存储过程和函数的方法
- 【转】java调用存储过程和函数
- 调用oracle函数与存储过程
- plsql 调用存储过程
- Mybatis调用存储过程和函数
- 数据库学习第二季第五集:编程语言的存储过程和函数机制及其编程语言的调用学习总结
- jdbc调用存储过程和函数
- OTL调用存储过程和函数