gpt4 book ai didi

java - 为什么Oracle的JDBC驱动不支持Oracle的Boolean类型

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:22:33 24 4
gpt4 key购买 nike

我是 JDBC 的新手,一直在玩弄它。论坛其他帖子说Oracle的JDBC驱动不支持Oracle PLSQL Boolean类型。我觉得这很奇怪:

来自oracle jdbc documentation看起来确实如此:

enter image description here

但是在another section它说它不允许将 BOOLEAN 参数传递给 PL/SQL 存储过程。

文档不是自相矛盾吗?

它不允许我传递或接受来自 PL/SQL 过程/函数的 boolean 值。它给了我以下异常:

Exception occured in the database
Exception message: Invalid column type: 16
Database error code: 17004
java.sql.SQLException: Invalid column type: 16
at oracle.jdbc.driver.OracleStatement.getInternalType(OracleStatement.java:3963)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameterInternal(OracleCallableStatement.java:135)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:304)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:393)
at oracle.jdbc.driver.OracleCallableStatementWrapper.registerOutParameter(OracleCallableStatementWrapper.java:1579)
at com.HrManager.insertNewEmployee(HrManager.java:1300)
at com.HrManager.main(HrManager.java:1411)

我想了解为什么 JDBC Oracle 驱动程序不支持 boolean 类型。是因为 PL/SQL "Boolean" 接受空值而 Java 的原始类型 "boolean" 不接受吗?

但与之相反的是,Java 的包装器类 "Boolean" 确实接受空值。这可以用来映射到 PLSQL 的 boolean 类型。有人可以对此有更多的了解吗。

最佳答案

发件人:PL/SQL TABLE, BOOLEAN, and RECORD Types

It is not feasible for Oracle JDBC drivers to support calling arguments or return values of the PL/SQL RECORD, BOOLEAN, or table with non-scalar element types. However, Oracle JDBC drivers support PL/SQL index-by table of scalar element types.

...

As a workaround to PL/SQL RECORD, BOOLEAN, or non-scalar table types, create container procedures that handle the data as types supported by JDBC. For example, to wrap a stored procedure that uses PL/SQL boolean, create a stored procedure that takes a character or number from JDBC and passes it to the original procedure as BOOLEAN or, for an output parameter, accepts a BOOLEAN argument from the original procedure and passes it as a CHAR or NUMBER to JDBC. Similarly, to wrap a stored procedure that uses PL/SQL records, create a stored procedure that handles a record in its individual components, such as CHAR and NUMBER, or in a structured object type. To wrap a stored procedure that uses PL/SQL tables, break the data into components or perhaps use Oracle collection types.

关于java - 为什么Oracle的JDBC驱动不支持Oracle的Boolean类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27132648/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com