Java calls the Oracle Stored Procedure

Source: Internet
Author: User

call the stored procedure with returned result set:

/*** Call the stored procedure with returned result set ** @ Param procname * @ Param * @ return * @ throws sqlexception * @ throws nofreeconnectionexception */Public datasource execuceproc (string procname, string [] PARAM) throws sqlexception, nofreeconnectionexception {connection con = NULL; callablestatement getresults = NULL; resultset rs = NULL; stringbuffer build = new stringbuffer (); build. append ("{call "). append (procname); build. Append ("("); If (Param! = NULL & Param. length> 0) {for (INT I = 0; I <Param. length; I ++) {build. append ("'"). append (Param [I]). append ("',") ;}} build. append ("?)} "); Try {con = connectdbbean. getconnection (readwritedbpool. readpool); getresults = con. preparecall (build. tostring (), resultset. type_scroll_sensitive, resultset. concur_updatable); getresults. registeroutparameter (1, oracletypes.cursorrentaskgetresults.exe cute (); RS = (resultset) getresults. getObject (1); this. rstodatasource (RS);} finally {try {If (RS! = NULL) {Rs. Close ();} If (getresults! = NULL) {getresults. close () ;}} catch (sqlexception e) {log. error (E);} connectdbbean. closeconnection (readwritedbpool. readpool, con);} return New datasourcetype ();} 

 

Call the stored procedure with parameters:

/*** Call the stored procedure with parameters ** @ Param procname * @ Param * @ return * @ throws sqlexception * @ throws nofreeconnectionexception */@ suppresswarnings ("unchecked ") public static void execuceproc (string procname, list PARAM) throws sqlexception, nofreeconnectionexception {connection con = NULL; callablestatement getresults = NULL; stringbuffer build = new stringbuffer (); build. append ("{call "). append (procname); Bui LD. append ("("); If (Param! = NULL & Param. size ()> 0) {for (INT I = 0; I <Param. size (); I ++) {if (I> 0) build. append (","); build. append ("'"). append (Param. get (I )). append ("'") ;}} build. append (")}"); try {con = connectdbbean. getconnection (readwritedbpool. readpool); getresults = con. preparecall (build. tostring (), resultset. type_scroll_sensitive, resultset.concur_updatableappsgetresults.exe cute ();} finally {try {If (getresults! = NULL) {getresults. Close () ;}} catch (exception e) {log. Error (E);} connectdbbean. closeconnection (readwritedbpool. readpool, con );}}


 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.