求一个完整的JAVA调用存储过程的代码,请给的详细,急,必解贴
下面是个存储过程,测试正常能用,想求一个根据这个存储过程,用JAVA做的调用代码。
请给出详细完整代码,不要只是代码片段,也不要说去网上找。小弟初学,想求一个调用这个存储过程java代码用来方便学习。谢谢,急,必解贴。
这个存储过程是输入两个值,根据值查询后得到一些输出值,JAVA代码要如何调用这个存储过程,如何得到并使用那些输出的值?请一定是完整的代码,谢
create or replace procedure SH_VEH_CX(存储 java sql
vhpzl IN varchar2,
vhphm IN varchar2,
vRES out varchar2,
VCLSBDH out varchar2,
VFDJH out varchar2,
VCLLX out varchar2,
VCSYS out varchar2,
Vsyxz out varchar2,
VSFZMHM out varchar2,
VSYR out varchar2,
Vsyq out varchar2,
Vccdjrq out date,
Vyxqz out date,
Vqzbfqz out date,
Vzt out varchar2,
Vsjhm out varchar2
)
IS
rowcount number;
begin
if length(vHPHM)<=5 then
vRES := 0;
return;
END IF;
select
CLSBDH,
FDJH,
CLLX,
CSYS,
syxz,
SFZMHM,
SYR,
syq,
ccdjrq,
yxqz,
qzbfqz,
zt,
sjhm
INTO
vCLSBDH,
vFDJH,
vCLLX,
vCSYS,
vsyxz,
vSFZMHM,
vSYR,
vsyq,
vccdjrq,
vyxqz,
vqzbfqz,
vzt,
vsjhm
from jx_VEHICLE
where HPHM=vHPHM AND HPZL=VHPZL and rownum=1;
rowcount := sql%rowcount;
if rowcount=1 then
vRES := 1;
else
vRES := 0;
end if;
exception
when OTHERS then
vRES := 0;
end SH_VEH_CX;
public static void main(String[] args) {
Test test = new Test();
String str1="a";
String str2="b";
String result = test.select(str1, str2);
//result算是输出值么?放到哪里?
}
//这里就是根据输入值进行sql查询的过程
public String select(String str1,String str2){
return "";
}
//调用存储过程的格式("{ call HYQ.TESTA(?,?) }")
callableStatement = connection.prepareCall("{ call SH_VEH_CX(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) }");
callableStatement.setString(1, "vhpzl");//输入参数
callableStatement.setString(2, "vhphm");
callableStatement.registerOutParameter(3, Types.VARCHAR);//输出参数
callableStatement.registerOutParameter(4, Types.VARCHAR);
callableStatement.registerOutParameter(5, Types.VARCHAR);
//......
callableStatement.registerOutParameter(12, Types.DATE);
callableStatement.registerOutParameter(13, Types.DATE);
callableStatement.registerOutParameter(14, Types.DATE);
callableStatement.registerOutParameter(15, Types.VARCHAR);
callableStatement.registerOutParameter(16, Types.VARCHAR);
callableStatement.execute();//执行存储过程
String vRES = callableStatement.getString(3);//获取输出参数
String VCLSBDH = callableStatement.getString(4);
String VFDJH = callableStatement.getString(5);
//......
String Vccdjrq = callableStatement.getString(12);
String Vyxqz = callableStatement.getString(13);
String Vqzbfqz = callableStatement.getString(14);
String Vzt = callableStatement.getString(15);
String Vsjhm = callableStatement.getString(16);
public static void main(String[] args) throws Exception {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL","name","password");
//调用存储过程的格式("{ call HYQ.TESTA(?,?) }")
CallableStatement callableStatement = connection.prepareCall("{ call SH_VEH_CX(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) }");
callableStatement.setString(1, "vhpzl");//输入参数
callableStatement.setString(2, "vhphm");
callableStatement.registerOutParameter(3, Types.VARCHAR);//输出参数
callableStatement.registerOutParameter(4, Types.VARCHAR);
callableStatement.registerOutParameter(5, Types.VARCHAR);
callableStatement.registerOutParameter(6, Types.VARCHAR);
callableStatement.registerOutParameter(7, Types.VARCHAR);
callableStatement.registerOutParameter(8, Types.VARCHAR);
callableStatement.registerOutParameter(9, Types.VARCHAR);
callableStatement.registerOutParameter(10, Types.VARCHAR);
callableStatement.registerOutParameter(11, Types.VARCHAR);
callableStatement.registerOutParameter(12, Types.DATE);
callableStatement.registerOutParameter(13, Types.DATE);
callableStatement.registerOutParameter(14, Types.DATE);
callableStatement.registerOutParameter(15, Types.VARCHAR);
callableStatement.registerOutParameter(16, Types.VARCHAR);
callableStatement.execute();//执行存储过程
String vRES = callableStatement.getString(3);//获取输出参数
String VCLSBDH = callableStatement.getString(4);
String VFDJH = callableStatement.getString(5);
String VCLLX = callableStatement.getString(6);
String VCSYS = callableStatement.getString(7);
String Vsyxz = callableStatement.getString(8);
String VSFZMHM = callableStatement.getString(9);
String VSYR = callableStatement.getString(10);
String Vsyq = callableStatement.getString(11);
String Vccdjrq = callableStatement.getString(12);
String Vyxqz = callableStatement.getString(13);
String Vqzbfqz = callableStatement.getString(14);
String Vzt = callableStatement.getString(15);
String Vsjhm = callableStatement.getString(16);
}