Oracle uses a stored procedure with input and output parameters. It is still a bit troublesome to use the stored procedure. If you are not careful about the parameter errors, you are advised to use them less if you can use them less. Here I want to use jdbc to share with you a simple stored procedure I have written myself. I have not studied the framework. In a few days, we will make up for you. 1. first, write a stored procedure with input and output parameters [SQL] create or replace procedure xxx (newfid In Number, newfname Out Varchar) www.2cto.com As begin Select fname Into newfname From m_student Where fid = newfid; end; note that varchar cannot be written As varchar2; otherwise, the input and output parameters do not match. run the stored procedure [java] package org. lxh; import java. SQL. callableStatement; import java. SQL. connection; import java. SQL. resultSet; import java. SQL. SQLException; import or Acle. jdbc. oracleCallableStatement; public class TestUse {public static void main (String [] args) throws Exception {DBConnection con = new DBConnection (); Connection getConn = con. getConnection (); OracleCallableStatement cs = (OracleCallableStatement) getConn. prepareCall ("{call xxx (newfid =>: newfid, newfname =>: newfname)}"); cs. setInt (1,365); www.2cto.com cs. registerOutParameter (2, java. SQL. types. VARCHAR); cs.exe cute (); String strAge = cs. getString (2); System. out. println ("fid is:" + strAge); getConn. close () ;}} OracleCallableStatement can be written as CallableStatement. input parameters do not need to be registered, but output parameters need to be registered. The most important thing to note is the data type. Otherwise, errors may occur.
Author: chenwill3