欢迎来到天天文库
浏览记录
ID:36203632
大小:116.50 KB
页数:17页
时间:2019-05-07
《java 调用 pl_sql ( 15 )》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、CS276AdvancedOracleUsingJavaChapter5PL/SQLandJDBCCallingPL/SQLProceduresChapter2showedthedefinitionofaPl/SQLprocedurenamedupdate_product_price().Thisproceduremaybeusedtoupdateapriceofproductintheproductstable.Theprocedureacceptstwoparameters.CallingPL/SQLProceduresTherearethree
2、stepsinvolvedincallingaPL/SQLprocedure:Step1:CreateandPrepareaCallableStatementObjectStep2:ProvideParameterValuesStep3:Calltheexecute()MethodCallingPL/SQLProceduresStep1:CreateandPrepareaCallableStatementObjectCallableStatementmyCallableStatement=myConnection.prepareCall("{call
3、update_product_price(?,?)}");CallingPL/SQLProceduresStep2:ProvideParameterValuesbindvaluestotheCallableStatementobject'sparametersmyCallableStatement.setInt(1,1);myCallableStatement.setDouble(2,1.1);CallingPL/SQLProceduresStep3:Calltheexecute()MethodmyCallableStatement.execute(
4、);Whenyou’refinishedwithyourCallableStatementobject,youshouldcloseit:myCallableStatement.close();CallingPL/SQLFunctionsTherearefivestepsinvolvedincallingaPL/SQLfunction:Step1:CreateandPrepareaCallableStatementObjectStep2:RegistertheOutputParameterStep3:ProvideParameterValuesSte
5、p4:RuntheCallableStatementStep5:ReadtheReturnValueCallingPL/SQLFunctionsStep1:CreateandPrepareaCallableStatementObjectcallthePL/SQLfunctionupdate_product_price_func()myCallableStatement=myConnection.prepareCall("{?=callupdate_product_price_func(?,?)}");CallingPL/SQLFunctionsSte
6、p2:RegistertheOutputParameterandbindvaluestotheCallableStatementobject'sparametersmyCallableStatement.registerOutParameter(1,java.sql.Types.INTEGER);CallingPL/SQLFunctionsThismethodacceptstwoparameters:thenumericalpositionoftheplaceholderfrothestringsuppliedtotheCallAbleStateme
7、ntobjectandthePL/SQLtypefortheoutputparameter.YoucanusePL/SQLtypefromconstantsdefinedinthe:java.sql.Typesclassororacle.jdbc.OracleTypesclassCallingPL/SQLFunctionsStep3:ProvideParameterValuesThefollowingexamplesbindtheintvalue1tosecondplaceholder(correspondstotheproductid)myCall
8、ableStatement.setInt(2,1);andbindthedouble0.8tothethir
此文档下载收益归作者所有