为什么Oracle的JDBC驱动程序不支持Oracle的布尔类型

为什么Oracle的JDBC驱动程序不支持Oracle的布尔类型

问题描述:

我是JDBC的新手,并且一直在使用它.论坛中的其他帖子表明Oracle的JDBC驱动程序不支持Oracle PLSQL布尔类型.我觉得那真的很奇怪:

I am new to JDBC and have been playing with it. Other posts in the forum indicate that Oracle's JDBC driver does not support Oracle PLSQL Boolean type. I find that really strange:

来自 oracle jdbc文档看起来确实如此:

但是在另一部分中表示不允许BOOLEAN参数传递给PL/SQL存储过程.

But in another section it says it does not allow passing of BOOLEAN parameters to PL/SQL stored procedures.

文档不是相互矛盾的吗?

Isn't the the documentation contradicting itself ?

它不允许我从PL/SQL过程/函数传递或接受布尔值.它给了我以下异常:

It does not let me pass or accept Boolean values from PL/SQL procedures/functions. It gives me the following exception:

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 Drivers不支持布尔类型.是因为PL/SQL "Boolean"接受空值,而Java的原始类型"boolean"不接受?

I am trying to understand why JDBC Oracle Drivers do not support Boolean types. Is it because PL/SQL "Boolean" accepts null values and Java's primitive type "boolean" does not ?

但与此相反的是,Java的包装器类"Boolean"确实接受空值.这可以用来映射到PLSQL的Boolean类型.有人可以对此进行更多介绍吗?

But the counter to it would be , Java's wrapper class "Boolean" does accept nulls. This can be used to map to PLSQL's Boolean type . Can some one throw more light on this.

来自: PL/SQL TABLE,BOOLEAN和RECORD类型

Oracle JDBC驱动程序不支持PL/SQL RECORD,BOOLEAN或具有非标量元素类型的表的调用参数或返回值.但是,Oracle JDBC驱动程序支持标量元素类型的PL/SQL索引表.

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.

...

作为PL/SQL RECORD,BOOLEAN或非标量表类型的解决方法,创建容器过程以将数据作为JDBC支持的类型进行处理.例如,要包装使用PL/SQL布尔值的存储过程,请创建一个存储过程,该存储过程从JDBC获取一个字符或数字,并将其作为BOOLEAN传递给原始过程,或者对于输出参数,从原始输入接受BOOLEAN参数.过程并将其作为CHAR或NUMBER传递给JDBC.同样,要包装使用PL/SQL记录的存储过程,请创建一个存储过程,以其单独的组件(例如CHAR和NUMBER)或结构化对象类型来处理记录.要包装使用PL/SQL表的存储过程,请将数据分解为组件,或者也许使用Oracle集合类型.

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.