调用 Oracle 过程

发布于 2024-12-28 13:36:00 字数 1497 浏览 0 评论 0原文

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一张白纸 2025-01-04 13:36:00

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

另外,请考虑对查询使用参数替换;此代码请求 SQL 注入 %)

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 %)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文