本文介绍了为什么JDBC不支持Oracle Boolean类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我刚刚接触JDBC,并且一直在玩。论坛中的其他帖子表明JDBC不支持Oracle PLSQL布尔类型。我觉得很奇怪: 从,它表示不允许将BOOLEAN参数传递给PL / SQL存储过程。 文档是否不矛盾? 它不允许我通过或接受PL / SQL中的布尔值过程/函数。它给了我以下例外: 数据库中发生异常异常消息:无效列类型:16 数据库错误代码:17004 java.sql.SQLException:无效的列类型:oracle.jdbc.driver.OracleStatement.getInternalType(OracleStatement.java:3963)中的 在oracle中。 jdbc.driver.OracleCallableStatement.registerOutParameterInternal(OracleCallableStatement.java:135)在oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:304)在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驱动程序不支持B零类型。是因为PL / SQL Boolean接受空值和Java的原始类型boolean不?但是它的计数器是Java的包装类Boolean确实接受null。这可以用于映射到PLSQL的布尔类型。可以有人在这个上多点光。解决方案来自: PL / SQL TABLE,BOOLEAN和RECORD Types Oracle JDBC驱动程序支持使用非标量元素类型支持调用参数或返回PL / SQL RECORD,BOOLEAN或表的值是不可行的。但是,Oracle JDBC驱动程序支持标量元素类型的PL / SQL索引表。 ... 作为PL / SQL RECORD,BOOLEAN或非标量表类型的解决方法,创建将数据作为JDBC支持的数据处理的容器过程。例如,要包装使用PL / SQL布尔值的存储过程,请创建一个存储过程,该过程从JDBC获取一个字符或数字,并将其传递给原始过程作为BOOLEAN,或者对于输出参数,从原始信息接受BOOLEAN参数并将其作为CHAR或NUMBER传递给JDBC。类似地,要包装使用PL / SQL记录的存储过程,请创建一个存储过程来处理其各个组件(如CHAR和NUMBER)或结构化对象类型中的记录。要包装使用PL / SQL表的存储过程,将数据分解为组件或可能使用Oracle集合类型。 I am new to JDBC and have been playing with it. Other posts in the forum indicate that JDBC does not support Oracle PLSQL Boolean type. I find that really strange:From the oracle jdbc documentation it seems like it does: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 ?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 databaseException message: Invalid column type: 16Database error code: 17004java.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)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 ?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. 解决方案 From: 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. 这篇关于为什么JDBC不支持Oracle Boolean类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-31 14:45