为了能够捕获Oracle数据库中的过程返回,请尝试此操作.
public static void main(String[] args) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:xe";
Connection con = DriverManager.getConnection(url, db_user, password);
System.out.println("Connected to database");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date now = new java.sql.Date(simpleDateFormat.parse("12/02/2001").getTime());
String command = "{call SALDOS(?,?)}";
CallableStatement cstmt = con.prepareCall(command);
cstmt.registerOutParameter(2, Types.DECIMAL);
cstmt.setDate(1, now);
cstmt.execute();
Double str = cstmt.getDouble(2);
cstmt.close();
System.out.println("Retorno: " + str);
} catch (Exception e) {
e.printStackTrace();
}
}
如果您使用不同的返回Map SimpleJdbcCall这样:
SimpleJdbcCall call = Util.getSimpleJdbcCallInstance();
call.setProcedureName("PROCED_CONDOMINIAL");
call.declareParameters(
new SqlParameter("CONDOMINIO", Types.VARCHAR),
new SqlParameter("BLOCO", Types.VARCHAR),,
new SqlOutParameter("P_NUMERO", Types.NUMERIC),
new SqlOutParameter("P_LOG", Types.VARCHAR));
Map parametros = new HashMap();
parametros.put("CONDOMINIO_IC", descricaoCondominio);
parametros.put("BLOCO_IC", imovelCondominial.getBloco());
Map out = call.execute(parametros);
BigDecimal chave = (BigDecimal) out.get("P_NUMERO");
imovelCondominial.setId(chave.longValue());
和程序的声明
create or replace PROCEDURE PROCED_CONDOMINIAL
(CONDOMINIO VARCHAR2,
BLOCO VARCHAR2,
NUMERO OUT NUMBER,
LOG OUT VARCHAR2) -- PARAMETROS DE SAIDAS (OUT).-
在这里工作.看看这个博客.
在Oracle 10xe和11xe上测试过.