java jdbc 命名参数,Java命名参数的名称(用于Oracle JDBC函数结果)

I'm going to call a function, and set some parameters by name, example:

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 function parameters are:

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

The question is how to register result as an out parameter, and then get it from oracle to java?

I can register in/out parameters by name, because I know theirs names from function, but I don't know how go get function result, what variable name use for it.

Manuals describe only usage in/out params with procedures, not functions.

Oracle version: 11.1.0.6.0

Java version: 1.6.0_14

解决方案

You register the function result as if it were the first parameter. Obviously, this shifts the numbering of the actual parameters.

Your already existing line

cs.registerOutParameter(1, OracleTypes.VARCHAR);

is all it takes. After the call, get your result like this:

String result = cs.getString(1);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值