java - Oracle 存储过程在 Linux 上运行时失败,在 Windows 上工作

标签 java linux oracle stored-procedures jdbc


我的程序声明为:

 PROCEDURE procName(id in number, string1 in varchar2, string2 in varchar2, userId in number, updateAll in number, out_ret out varchar2);

当我尝试在 Windows 或 SQL Developer 中执行此过程时,它可以完美运行。 问题来了,当在 linux 机器(centOs 7.1)上运行相同的 jar 时:oracle 抛出异常:

java.sql.SQLException: ORA-01403: no data found
ORA-01403: no data found
ORA-06512: at 'foo', line 15
ORA-04088: error during execution of trigger 'bar'
...

代码如下:

public static Boolean callTest(long id, String string1,
 String string2, long   employeeId) {
    Connection conn = null;
    CallableStatement callableStatement = null;
    Boolean ret = true;
    try {
        conn = getDBConnection();
        conn.setAutoCommit(false);
        callableStatement = conn.prepareCall("{ CALL proc_name(?,?,?,?,?,?) }");
        callableStatement.setLong(1, id);
        callableStatement.setString(2, string1);
        callableStatement.setString(3, string2);
        callableStatement.setLong(4, employeeId);
        callableStatement.setBoolean(5, true);
        callableStatement.registerOutParameter(6, java.sql.Types.VARCHAR);
        callableStatement.execute();
        String out = callableStatement.getString(6);
        log.info("Procedure returned:" + out);
        conn.rollback();

    } catch (SQLException e) {
        log.info("Procedure exception:" + e.getLocalizedMessage());
    } finally {
        if (callableStatement != null) {
            try {
                callableStatement.close();
            } catch (SQLException e) {
                log.info("Error trying to close statement:" +     e.getLocalizedMessage());
            }
        }

        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                log.info("Error trying to close connection:" + e.getLocalizedMessage());
            }
        }
    }
    return ret;

}

private static Connection getDBConnection() {

    Connection dbConnection = null;

    try {
        Class.forName("net.sf.log4jdbc.DriverSpy");
        dbConnection = DriverManager.getConnection(
                DB_CONNECTION, DB_USER,
                DB_PASSWORD);
    } catch (SQLException e) {

        log.info("error creating connection" + e.getLocalizedMessage());

    } catch (ClassNotFoundException e) {
        log.info("error creating connection" + e.getLocalizedMessage());
    }

    return dbConnection;
}

调用的参数是一样的。
这个问题的原因是什么?

@编辑 1
Jar是在windows上创建的,然后在windows和linux上运行,所以两个系统的DB url、用户和密码都是一样的。

@编辑 2 我无法提供任何程序或触发代码,我没有。

最佳答案

谢谢@AlexPoole ,
你的猜测是对的, 程序正在获取客户端用户名,
并在数据库中查找它。 不幸的是,Windows 和 Linux 上的系统用户不同。

关于java - Oracle 存储过程在 Linux 上运行时失败,在 Windows 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33545326/

相关文章:

SQL group by "date"问题

python - 在树莓派上自动运行命令

java - 在 Maven 构建的 JAR 中找不到 Jersey 消息正文阅读器

java - LinkedIn Wherehows - 如何启动后端?

java - 使用控制台使用git,使用IDE(Eclipse)开发时需要考虑哪些事项?

c - 仅在 "if loop"内的 "while loop"中打印一次

linux - 生产中使用的是单cloudera单用户模式吗?

sql-server - 在 SQL Server 中,如何通过链接服务器连接查询 Oracle Timestamp 列?

oracle - 调用oracle过程后可以回滚吗?

java - g1 gc 中的 `Ref Enq` 实际做了什么