How to handle callableStatement.registerOutParameter(1, java.sql.Types.BOOLEAN);

徘徊边缘 提交于 2019-12-04 05:21:21

问题


Have a stored procedure in Oracle 10g/11g like the following:

CREATE OR REPLACE 
PROCEDURE SP_SOME_PROC (  PRM_ID IN NUMBER , START_DATE IN DATE,  RESULT OUT BOOLEAN) 
is...

Using the following to code to call it and get the result:

String sql = "{call SP_SOME_PROC(?,?,?) }";

callableStatement = conn.prepareCall(sql);
callableStatement.setLong(1, theid);
callableStatement.setDate(2,  new java.sql.Date(startDate.getTime()));
callableStatement.registerOutParameter(3, java.sql.Types.BOOLEAN);

callableStatement.executeUpdate();

Boolean result = callableStatement.getBoolean(3);

the code above yields, however, an exception like the following

[10/8/13 2:28:24:736 EEST] 0000009a SystemErr     R java.sql.SQLException: Invalid column type: 16
[10/8/13 2:28:24:737 EEST] 0000009a SystemErr     R     at oracle.jdbc.driver.OracleStatement.getInternalType(OracleStatement.java:3950)
[10/8/13 2:28:24:737 EEST] 0000009a SystemErr     R     at oracle.jdbc.driver.OracleCallableStatement.registerOutParameterInternal(OracleCallableStatement.java:135)
[10/8/13 2:28:24:737 EEST] 0000009a SystemErr     R     at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:304)
[10/8/13 2:28:24:737 EEST] 0000009a SystemErr     R     at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:393)
[10/8/13 2:28:24:737 EEST] 0000009a SystemErr     R     at oracle.jdbc.driver.OracleCallableStatementWrapper.registerOutParameter(OracleCallableStatementWrapper.java:1569)

I experimented other combinations such as

String sql = "{? = call SP_SOME_PROC(?,?) }";
callableStatement = conn.prepareCall(sql);
callableStatement.registerOutParameter(1, OracleTypes.BOOLEAN);

but no luck!


回答1:


While Oracle has a boolean type you can use in stored procedures, it does not have a boolean column type that can be sent across the JDBC interface. You are going to have to do some impedance matching (i.e. return int 0 & 1 or char 'T' and 'F').

This lack of a boolean column type is a holdover from ANSI, a source of much wailing and gnashing of teeth on the Oracle forums (look up 'boolean' on AskTom).



来源:https://stackoverflow.com/questions/19236673/how-to-handle-callablestatement-registeroutparameter1-java-sql-types-boolean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!