jdbc调用Oracle数据库存储过程.docx
文本预览下载声明
/blog/1582331Java jdbc调用Oracle数据库存储过程一、了解CallableStatement接口1.callablestatement接口提供了两种调用形式{?= call procedure-name[(arg1,arg2, ...)]} //包含结果参数的调用形式 如:函数(funciton){call procedure-name[(arg1,arg2, ...)]} //不包含结果参数的调用形式 如:存储过程(procedure)2.callablestatement接口提供的方法Java代码 void registerOutParameter(int parameterIndex, int sqlType) throws SQLException; //在调用存储过程的时候设置输出参数的类型,用于接收输出结果 void registerOutParameter(int parameterIndex, int sqlType) throws SQLException; //在调用存储过程的时候设置输出参数的类型,用于接收输出结果registerOutParameter接口中有四个该方法的重载实现,具体的可以查看源码了解Java代码 setXXX(int parameterIndex,XXX x) //主要用于设置过程调用时候需要的输入参数信息 其中XXX代表对应类型 setXXX(int parameterIndex,XXX x) //主要用于设置过程调用时候需要的输入参数信息 其中XXX代表对应类型Java代码 getXXX(int x) //主要用于获取过程调用后返回的参数的信息 getXXX(int x) //主要用于获取过程调用后返回的参数的信息3.callablestatement接口产生的异常提示如下源码:Java代码 /* * @exception SQLFeatureNotSupportedException if codesqlType/code is * a codeARRAY/code, codeBLOB/code, codeCLOB/code, * codeDATALINK/code, codeJAVA_OBJECT/code, codeNCHAR/code, * codeNCLOB/code, codeNVARCHAR/code, codeLONGNVARCHAR/code, * codeREF/code, codeROWID/code, codeSQLXML/code * or codeSTRUCT/code data type and the JDBC driver does not support * this data type * @see Types */ void registerOutParameter(int parameterIndex, int sqlType) ows SQLException; /* * @exception SQLFeatureNotSupportedException if codesqlType/code is * a codeARRAY/code, codeBLOB/code, codeCLOB/code, * codeDATALINK/code, codeJAVA_OBJECT/code, codeNCHAR/code, * codeNCLOB/code, codeNVARCHAR/code, codeLONGNVARCHAR/code, * codeREF/code, codeROWID/code, codeSQLXML/code * or codeSTRUCT/code data type and the JDBC driver does not support * this data type * @see Types */ void registerOutParameter(int parameterIndex, int sqlType)throws SQLException; 当我们使用registerOutParameter方法设置输出参数类型的时候,需要注意对于某一些类型是不能够进行设置的如上中所以提到的类型都会引发SQLFeatureNotSupportedException异常,对于能够支持的类型可以查看java.sql.Types和oracle.jdbc.OracleTypes如下源码:Java代码 /* * java.sql.
显示全部