2024年4月11日发(作者:)

/blog/1582331

Java jdbc调用Oracle数据库存储过程

一、了解CallableStatement接口

lestatement接口提供了两种调用形式

{?= call [(,, ...)]} //包含结果参数的调用

形式 如:函数(funciton)

{call [(,, ...)]} //不包含结果参数的调用

形式 如:存储过程(procedure)

lestatement接口提供的方法

Java代码

1. void registerOutParameter(int parameterIndex, int sqlType)

2. throws SQLException; //在调用存储过程的时候设置输出参数的类型,

用于接收输出结果

registerOutParameter接口中有四个该方法的重载实现,具体的可以查看源

码了解

Java代码

1. setXXX(int parameterIndex,XXX x) //主要用于设置过程调用时候需要

的输入参数信息 其中XXX代表对应类型

Java代码

1. getXXX(int x) //主要用于获取过程调用后返回的参数的信息

lestatement接口产生的异常提示

如下源码:

Java代码

1. /*

2. * @exception SQLFeatureNotSupportedException if

sqlType is

3. * a ARRAY, BLOB, CLOB,

4. * DATALINK, JAVA_OBJECT,

NCHAR,

5. * NCLOB, NVARCHAR,

LONGNVARCHAR,

6. * REF, ROWID, SQLXML

7. * or STRUCT data type and the JDBC driver does not

support

8. * this data type

9. * @see Types

10.*/

registerOutParameter(int parameterIndex, int sqlType)

SQLException;

当我们使用registerOutParameter方法设置输出参数类型的时

候,需要注意对于某一些类型是不能够

进行设置的如上中所以提到的类型都会引发

SQLFeatureNotSupportedException异常,对于能够支持

的类型可以查看和Types

如下源码:

Java代码

1. /*

2. * eption: 不允许的操作: Ordinal binding and Named

binding cannot be

3. * combined! at

4. *

qlException(DatabaseErro

:112) at

5. *

qlException(DatabaseErro

:146) at

6. * oracle

7. * .e(OracleCallableSt

8. * :4219) at