简体   繁体   English

从 Java Web 应用程序调用 Oracle 存储过程

[英]Calling Oracle Stored Procedure from Java Web application

I am trying to call several oracle stored procedures from my web application.我正在尝试从我的 web 应用程序中调用几个 oracle 存储过程。 There are no in or out parameters in any of the procedures.在任何过程中都没有输入或输出参数。 Everything works perfectly when I run my web app locally, but when I deploy the app to our test server the stored procedure calls stop working.当我在本地运行我的 web 应用程序时,一切正常,但是当我将应用程序部署到我们的测试服务器时,存储过程调用停止工作。 I get no error messages and the procedure does not run.我没有收到任何错误消息,并且程序没有运行。

I would think it has something to do with the JDBC driver or connection, but I'm at a loss?我认为这与 JDBC 驱动程序或连接有关,但我不知所措? Any help would be greatly appreciated!任何帮助将不胜感激!

Here is the code that works perfectly when running locally and debugging:这是在本地运行和调试时完美运行的代码:

public boolean deleteFromTempTables(String id)
{
    String msg = "";
    CallableStatement stmt1 = null;
    
    try
    {
       conn = DBConnection.getConnection();
       
       DbmsOutput dbmsOutput = new DbmsOutput( conn );

       dbmsOutput.enable( 1000000 );
       
       stmt1 = conn.prepareCall("{call delete_from_temp_employee()}");
       stmt1.execute();
       stmt1.close();
       
       dbmsOutput.show(id);

       dbmsOutput.close();
    }
    catch(Exception e)
    {
        e.printStackTrace();
        return true;
    }
    finally
    {
        try 
        {
            stmt1.close();
            conn.close();

        } 
        catch (SQLException e) 
        {
            e.printStackTrace();
        }
    }
    return false;
}

Here is the stored procedure:这是存储过程:

create or replace procedure delete_from_temp_employee as 
temp_empe_before NUMBER;
temp_empe_after  NUMBER;

begin

    select count(*) into temp_empe_before from temp_employee;
    delete from temp_employee;
    select count(*) into temp_empe_after from temp_employee;

    DBMS_OUTPUT.PUT_LINE ('Procedure DELETE_FROM_TEMP_EMPLOYEE Employee Before:  ' || temp_empe_before);
    DBMS_OUTPUT.PUT_LINE ('Procedure DELETE_FROM_TEMP_EMPLOYEE Employee After:  ' || temp_empe_after);

end delete_from_temp_employee;

Call in JSP page:在 JSP 页面调用:

<%

boolean isDeleteError = false; 
isDeleteError = memberupload.deleteFromTempTables(userid);

%>

you need to execute:你需要执行:

set serveroutput ON;

this command makes output works.此命令使 output 工作。

also after delete statement add commit;同样在删除语句后添加commit; command to commit changes if you forget it.如果您忘记了提交更改的命令。

by the way, you can get the affected rows for DML statements like delete statement by using sql%rowcownt as following:顺便说一句,您可以使用 sql%rowcownt 获取 DML 语句(如删除语句)的受影响行,如下所示:

set serveroutput ON;
create or replace procedure delete_from_temp_employee2 as 
 rows NUMBER; 
begin

  delete from temp_employee;
  rows := SQL%rowcount; 


  DBMS_OUTPUT.PUT_LINE ('Deleted: ' || rows || ' row(s)'); 

end delete_from_temp_employee2;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM