Pregunta

I have a method that calls an oracle procedure at the same time as it inserts into oracle, the insert statement works but the procedure does not. I am not receiving any errors. can anyone see why this isnt working?

Class.forName("oracle.jdbc.driver.OracleDriver");
String connectionString = "jdbc:oracle:thin:@" + oracle_ip_address + ":" + oracle_db_port + ":" + oracle_db_sid;
Connection conn = DriverManager.getConnection(connectionString, oracle_db_username, oracle_db_password);

ResultSet rs = stmt.executeQuery("Select * from Dropper"); 

CallableStatement cs = conn.prepareCall("{ call TTMS.job_vacationconflict_notify(?,?,?)}");

SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");

    Statement stmt2 = conn.createStatement();

    while (rs.next()){
        String di = rs.getString("DROPPER_ID");
        String sd = rs.getString("BEGIN_DT").replace(" 00:00:00.0", "");
        String ed = rs.getString("END_DT").replace(" 00:00:00.0", "");
        String vi = rs.getString("VACATION_ID");
        String md = rs.getString("MODIFY_DT").replace(" 00:00:00.0", "");

        query = "INSERT INTO DROPPER_VACATIONS(DROPPER_ID, BEGIN_DT, END_DT, CREATE_DT, CREATE_BY, MODIFY_DT, MODIFY_BY, COMMENTS, VACATION_ID) "
        + "VALUES ('"+di+"',to_date('"+sd+"','YYYY-MM-DD'),to_date('"+ed+"','YYYY-MM-DD'),sysdate,'MJRUTLED',to_date('"+md+"','YYYY-MM-DD'),'MJRUTLED','','"+vi+"')";

        stmt2.executeUpdate(query);

        cs.setInt(1,Integer.parseInt(di));
        cs.setString(2,sdf.parse(sd).toString());
        cs.setString(3,sdf.parse(ed).toString());

        cs.execute();
    }
¿Fue útil?

Solución

Does your procedure expect dates as input? If it does, try to pass date values and not rely on implicit conversion. If the SP expects strings, make sure you format the dates exactly the same way that the SP expects (add debug print on both sides, dbms_output and dbms_pipe are your friends).

Also, please consider using parameter substitution for query; this code begs for SQL injection %)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top