简体   繁体   English

如何通过JDBC将Java存储过程加载到Oracle 10g中?

[英]How to load Java Stored Procedure through JDBC into Oracle 10g?

I'm trying to load some java stored procedures into an Oracle 10g database through JDBC. 我正在尝试通过JDBC将一些Java存储过程加载到Oracle 10g数据库中。 The statement I'm executing is - 我正在执行的声明是 -

CREATE OR REPLACE JAVA SOURCE NAMED "test.Test" AS
package test;
public class Test {
    public static String myMethod(String a) {
        return a;
    }
};

Running this through TOAD works just fine, but when running through my JDBC client gives the following error - 通过TOAD运行这个工作正常,但是当通过我的JDBC客户端运行时出现以下错误 -

Exception in thread "Thread-3" java.lang.NullPointerException
        at oracle.jdbc.driver.T4C8Oall.getNumRows(T4C8Oall.java:728)
        at oracle.jdbc.driver.T4CStatement.execute_for_rows(T4CStatement.java:478)
        at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1028)
        at oracle.jdbc.driver.OracleStatement.executeUpdate(OracleStatement.java:1451)
        at ejsdal.CreateDBJavaSQL.executeScript(CreateDBJavaSQL.java:23)
        at ejsdal.OperationController.run(OperationController.java:182)

I'm using the java.sql.Statement's "executeUpdate" passing the string in the first code block. 我正在使用java.sql.Statement的“executeUpdate”在第一个代码块中传递字符串。

It is possible to load java source through JDBC? 可以通过JDBC加载java源码吗?

Figured it out - need to set the 想出来 - 需要设置

statement.setEscapeProcessing(false);

before executing the update. 在执行更新之前。 This is because the Java source file's { and } characters are misinterpreted as procedure call syntax by the JDBC driver. 这是因为JDBC驱动程序将Java源文件的{}字符误解为过程调用语法。

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

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