1.无参数调用方式
//Storeprocedure 为存储过程名
CallabelStatement cstm = con.prepareCall("{call Storeprocedure()}");
ResultSet rs = cstm.executeQuery();2.有参数调用方式//Storeprocedure 为存储过程名
CallabelStatement cstm = con.prepareCall("{call Storeprocedure(?,?)}");
//登记输出参数,根据参数类型不同而改变java.sql.Types的值
cstm.registerOutParameter(1,java.sql.Types.TINYINT);
cstm.registerOutParameter(2,java.sql.Types.DECIMAL,2);
//执行
cstm.executeUpdate();
//获取输出参数的值
byte x = cstm.getByte(1);
Numeric n = cstm.getNumeric(2,2);
//Storeprocedure 为存储过程名
CallabelStatement cstm = con.prepareCall("{call Storeprocedure()}");
ResultSet rs = cstm.executeQuery();2.有参数调用方式//Storeprocedure 为存储过程名
CallabelStatement cstm = con.prepareCall("{call Storeprocedure(?,?)}");
//登记输出参数,根据参数类型不同而改变java.sql.Types的值
cstm.registerOutParameter(1,java.sql.Types.TINYINT);
cstm.registerOutParameter(2,java.sql.Types.DECIMAL,2);
//执行
cstm.executeUpdate();
//获取输出参数的值
byte x = cstm.getByte(1);
Numeric n = cstm.getNumeric(2,2);
statement.setBinaryStream(......);
或者用另一个方法.我记得我在sql server里是这样做的,试试看吧.
import javax.sql.*;
import java.util.*;
import java.io.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/public class Main {
public static void main(String[] args) {
String JDBC_DRIVER_CLASS = "oracle.jdbc.driver.OracleDriver";
String DB_URL = "jdbc:oracle:thin:@192.168.1.230:1521:shanghai";
String DB_USERID = "ronsun";
String DB_PASSWORD = "nopwd";
Connection con=null;
String strCallSt="";
int fileLength=0;
CallableStatement cs=null;
try {
Class.forName(JDBC_DRIVER_CLASS);
con=DriverManager.getConnection(DB_URL, DB_USERID, DB_PASSWORD);
FileInputStream is=new FileInputStream("d:\\a.jpg");
fileLength=(int)is.available();
strCallSt = "{? = call sp(?,?,?,?)}";
cs = con.prepareCall( strCallSt );
cs.setBinaryStream(1,is,fileLength);
cs.registerOutParameter(1,Types.INTEGER);
cs.execute();
System.out.println("Return result:"+cs.getInt(1));
}
catch (Exception ex) {
ex.printStackTrace();
} }
}