调用Oracle过程

时间:2012-01-23 20:48:41

标签: java oracle callable-statement

我有一个方法在插入oracle的同时调用oracle过程,insert语句有效但过程没有。我没有收到任何错误。谁能明白为什么这不起作用?

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();
    }

1 个答案:

答案 0 :(得分:0)

您的程序是否期望日期作为输入?如果是,请尝试传递日期值,而不是依赖隐式转换。如果SP需要字符串,请确保将日期格式设置为与SP期望的完全相同(在双方添加调试打印,dbms_outputdbms_pipe是您的朋友)。

另外,请考虑使用query的参数替换;此代码 begs 用于SQL注入%)