从可调用语句 OUT 参数中检索意外的 null
我有两个过程:一个链接到静态方法 O.execute() 的 java 存储过程 JAVA_P() 和一个 pl/sql 过程 SQL_P(in_param IN CUSTOM_TYPE_1, out_param OUT CUSTOM_TYPE_2)。
JAVA_P 使用 CallableStatement 调用 SQL_P。
现在是一个大WTF: 当我在 oracle 外部(从外部 jvm)运行 O.execute() 时,收到的 out_param 按预期设置。 当我将 O.execute() 作为 JAVA_P() (使用 oracle 内置 jvm)运行时,out_param 设置为 null(SQL_P 毫无例外地执行,并且应设置输出参数)。
您知道为什么会发生这种情况吗?
Oracle 数据库 10g 企业版版本 10.2.0.5.0 - 64bi 用于测试的 JRE 版本为 1.4.2_04。 JDBC 版本 10.2.0.3.0
@Juergen Hartelt 我的英语可能不够好,无法清楚地解释这一点,但我会尝试这种方式:
1)我像往常一样使用我的 IDE 编写了一些 java 代码:
public class P141_JAVABridge
{
public static void execute()
{
String databaseDriver = "oracle.jdbc.driver.OracleDriver";
String databaseUrl = "jdbc:oracle:thin:@xxx:1521:orcl";
String databaseUsername = "xxx";
String databasePassword = "xxx";
ods.setDriverType(databaseDriver);
ods.setURL(databaseUrl);
ods.setUser(databaseUsername);
ods.setPassword(databasePassword);
connection = ods.getConnection();
.... some code
map.put("custom_T",Custom_T_SQLData.class);
CallableStatement call = connection.prepareCall("call P141(?,?)");
call.setObject(1,inputObjectReference);
call.registerOutParameter(2,OracleTypes.STRUCT,"custom_T");
call.execute();
.... some code
}
}
2)我运行此代码 - wooha !它有效
3) 我已更改
connection = ods.getConnection();
为
connection = DriverManager.getConnection("jdbc:default:connection:");
4) 编译并将类加载到 oracle
5) 我已将 P141_JAVABridge.execute() 与 P141_JB 链接
create or replace PROCEDURE P141_JB () IS LANGUAGE JAVA NAME 'x.y.z.P141_JAVABridge.execute()';
6) 然后我执行 P141_JB
SET SERVEROUTPUT ON;
BEGIN
...some code
P141_JB();
...some code
END;
并在以下位置得到 NullPointerException
((Custom_T_SQLData)call.getObject(2)).responseStatus
I have two procedures: a java stored procedure JAVA_P() which is linked to a static method O.execute() and a pl/sql procedure SQL_P(in_param IN CUSTOM_TYPE_1, out_param OUT CUSTOM_TYPE_2).
JAVA_P calls SQL_P with CallableStatement.
And now a big WTF:
When I run O.execute() outside oracle (from external jvm) received out_param is set as expected.
When I run O.execute() as JAVA_P() (using oracle built-in jvm) then out_param is set to null (SQL_P is executed without exception and output parameter should be set).
Do you have any ideas why this happens?
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
JRE version used for tests 1.4.2_04.
JDBC version 10.2.0.3.0
@Juergen Hartelt my english may not be good enought to explain this clearly but i will try this way:
1) i have write some java code using as usual my IDE:
public class P141_JAVABridge
{
public static void execute()
{
String databaseDriver = "oracle.jdbc.driver.OracleDriver";
String databaseUrl = "jdbc:oracle:thin:@xxx:1521:orcl";
String databaseUsername = "xxx";
String databasePassword = "xxx";
ods.setDriverType(databaseDriver);
ods.setURL(databaseUrl);
ods.setUser(databaseUsername);
ods.setPassword(databasePassword);
connection = ods.getConnection();
.... some code
map.put("custom_T",Custom_T_SQLData.class);
CallableStatement call = connection.prepareCall("call P141(?,?)");
call.setObject(1,inputObjectReference);
call.registerOutParameter(2,OracleTypes.STRUCT,"custom_T");
call.execute();
.... some code
}
}
2) i run this code - wooha! it works
3) i have changed
connection = ods.getConnection();
to
connection = DriverManager.getConnection("jdbc:default:connection:");
4) compile and load class into oracle
5) i have linked P141_JAVABridge.execute() with P141_JB
create or replace PROCEDURE P141_JB () IS LANGUAGE JAVA NAME 'x.y.z.P141_JAVABridge.execute()';
6) then i executed P141_JB
SET SERVEROUTPUT ON;
BEGIN
...some code
P141_JB();
...some code
END;
and got NullPointerException at
((Custom_T_SQLData)call.getObject(2)).responseStatus
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经按照 Tolls 的建议做了,我已经把“call P141(?, ?)”放入大括号:
TADA!有用。
I have done as Tolls adviced me and I have put "call P141(?,?)" into braces:
TADA! It works.