浅谈Java存储过程调用(2)

第二种情况:有返回值的存储过程(返回值非列表).

存储过程为:

create or replace procedure test_b(param1 in varchar2,param2 out varchar2)
as
begin
select tname into param2 from test where tid=param1;
end;
Java调用代码:

package com.test;
import java.sql.*;
import java.io.*;
import java.sql.*;
public class TestProcB
{
public TestProcB(){
}
public static void main(String[]args)
{
Connection conn=null;
CallableStatement proc=null;
try{
Class.forName("Oracle.jdbc.driver.OracleDriver");
conn=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:test","test","test");
proc=conn.prepareCall("{calltest_b(?,?)}");
proc.setString(1,"1001");
proc.registerOutParameter(2,Types.VARCHAR);
proc.execute();
System.out.println("Outputis:"+proc.getString(2));
}catch(Exception e){
e.printStackTrace();
}finally{
try{

if(null!=proc){
proc.close();
}

if(null!=conn){
conn.close();
}

}catch(Exceptionex){

}
}
}
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwpgjy.html