从 Java 调用 Oracle 存储过程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3674841/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Calling Oracle stored procedure from Java
提问by javaguy
I'm calling an Oracle stored function using JDBC
thin driver.
Following is the code.
我正在使用JDBC
瘦驱动程序调用 Oracle 存储函数。
以下是代码。
class testSP
{
public static void main (String args [])
throws SQLException, ClassNotFoundException
{
String driver_class = "oracle.jdbc.driver.OracleDriver";
String connect_string = "jdbc:oracle:thin:@xxx.xx.xx.xx:1521:xxxx";
Connection conn;
Class.forName(driver_class);
conn = DriverManager.getConnection(connect_string, "xxxx", "xxxx");
// OracleCallableStatement ocs =
// (OracleCallableStatement)conn.prepareCall(
// "{? = call acpks_stmt_gen.fn_stmt_gen(?,?,?,?,?,?)}");
CallableStatement ocs =
conn.prepareCall(
"{? = call acpks_stmt_gen.fn_stmt_gen(?,?,?,?,?,?)}");
ocs.registerOutParameter(1, java.sql.Types.ARRAY);
ocs.setString(2, "144000014");
ocs.setString(3, "RET");
ocs.setString(4, "N");
ocs.setString(5, "3");
ocs.setNull(6, java.sql.Types.DATE) ;
ocs.setNull(7, java.sql.Types.DATE);
ocs.executeUpdate();
// java.sql.ResultSet rs2 = (java.sql.ResultSet) ocs.getResultSet();
}
}
When I call this I get an exception as following
当我调用它时,我得到如下异常
Exception in thread "main" java.sql.SQLException: ORA-03115: unsupported network datatype or representation
I'm using the thin driver ojdbc6.jar
provided by Oracle.
and I'm using this in my class path.
我正在使用ojdbc6.jar
Oracle 提供的瘦驱动程序。
我在我的课程路径中使用它。
Thanks.
谢谢。
回答by Erich Kitzmueller
Try
尝试
ocs.setString(6, "") ;
ocs.setString(7, "");
instead of
代替
ocs.setNull(6, java.sql.Types.DATE);
ocs.setNull(7, java.sql.Types.DATE);
making use of the fact that in Oracle, the empty string is the same as NULL.
利用在 Oracle 中,空字符串与 NULL 相同的事实。
In my current project, I've encountered similar problems with NULLs that could be solved that way. (Yes, that's fugly)
在我当前的项目中,我遇到了可以通过这种方式解决的 NULL 的类似问题。(是的,这很糟糕)