为了能够在 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();
}
}
如果您以这种方式使用不同的 Returns 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<String, Object> parametros = new HashMap<String, Object>();
parametros.put("CONDOMINIO_IC", descricaoCondominio);
parametros.put("BLOCO_IC", imovelCondominial.getBloco());
Map<String, Object> 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).-
在这里工作。看看这个博客。
http://jameajudo.blogspot.com.br/2009/03/call-procedure-oracle-with-java-and.html
在 Oracle 10xe 和 11xe 上测试。