Java: calling a stored procedure in an oracle database

EDIT: although some answers in this question may help other people with various problems, the solution is really related to some error with the automatic commit function in connection with the database! When forcing after the query was executed, the database reflected the changes, so the code below is the correct way to call a stored procedure of this type

I am trying to call a simple stored procedure in an oracle database.

The procedure is as follows:

procedure clear_orderProcDtlByOrdId(p_order_id in order_header.order_id%type,
                                    p_transaction_id in sl_order_processing_dtl.transaction_id%type DEFAULT NULL,
                                    p_item_action_id in sl_order_processing_dtl.item_action_id%type DEFAULT NULL )
...

The java code I'm having problems with looks like this:

    try 
    {
        CallableStatement storedProc = conn.prepareCall("{call PKG_PI_FRAUD.clear_orderProcDtlByOrdId(?)}");
        storedProc.setString(1, orderID);
        storedProc.execute();
    } 
    catch (SQLException e) 
    {
        e.printStackTrace();
    }

, . SQL Developer, . , - , , , .

!

+5
2

, ! , , , !

+1

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.

+1

All Articles