【发布时间】:2011-04-11 14:57:32
【问题描述】:
我要调用一个函数,并按名称设置一些参数,例如:
Connection c = null;
ResultSet rs = null;
String query;
PreparedStatement ps;
CallableStatement cs = null;
try {
c = DbUtils.getConnection();
cs = c.prepareCall("{? = call get_proc_name(?, ?) }");
cs.registerOutParameter(1, OracleTypes.VARCHAR);
cs.setInt("in_proc_type", ProcTypes.SELECT);
cs.setLong("in_table_id", tableId);
// here I should use something like cs.registerOutParameter("result", OracleTypes.VARCHAR);
cs.execute();
PL/SQL 函数参数为:
CREATE OR REPLACE FUNCTION get_proc_name
(
in_proc_type IN NUMBER, /*1 - insert, 2 - update, 3 - delete, 4 - select*/
in_table_name IN VARCHAR2 := NULL,
in_table_id IN NUMBER := NULL,
in_table_type_id IN NUMBER := NULL,
is_new IN NUMBER := 0
) RETURN VARCHAR2
问题是如何将result注册为out参数,然后从oracle获取到java? 我可以通过名称注册输入/输出参数,因为我从函数中知道它们的名称,但我不知道如何获取函数结果,使用什么变量名。
手册仅描述过程中的输入/输出参数的用法,而不是函数。
Oracle 版本:11.1.0.6.0 Java版本:1.6.0_14
【问题讨论】:
标签: java jdbc named-parameters