Java read Oracle stored procedure return cursor (CURSOR) format read to list

Source: Internet
Author: User

/** *  Execute Stored procedure (currently only supports returning one cursor)  never null *  *  @param  sql *              executed statements  *  @param  index *              subscript of the current cursor  *  @param  obj  *             parameters (used to replace the? in SQL statements)  *  @param  rop *             Register the output parameters of Oracle (note that if the subscript is 1, the input parameter is 2 output parameter  *              the cursor is to be obtained by the subscript of the output parameter, if the subscript 3 to 6 is the input parameter, 7 output parameter, then obtains the content according to the 7th, and so on ....)  *            resultset rs = *             oraclecallablestatement.getcursor ( The subscript must be aligned with the subscript at the time of registration); *  @return &NBSP;&NBSP;*/PUBLIC&NBSP;LIST&LT;MAP&LT String, object>> searchtomaplistforproduce (string sql,int index, object  Obj[], int[] rop)  {List<Map<String, Object>> l = new  Arraylist<map<string, object>> (); Connection userconn = ins.getconn ();try {oraclecallablestatement ocs =  ( oraclecallablestatement)  userconn.preparecall (SQL); // callablestatement cs =  Con.preparecall (SQL); Ocs.registeroutparameter (index, rop[0]);//  register the output parameters, so you can register with the loop for  (int  i = 0; i < obj.length; i++)  {ocs.setobject (i + 1,  Obj[i]);}   Set parameter Ocs.execute (); Resultset rs = ocs.getcursor (Index);//  This method is Oracle's special if  (rs != null)  { Int cl = rs.getmetadata (). getColumnCount ();while  (Rs.next ())  {Map<String,  Object> each = new hashmap<sTring, object> ();for  (int i = 0; i < cl; i++)  {String  key = rs.getmetadata (). getColumnName (i + 1); object val = rs.getobject (key); Each.put (key, val);} L.add (each);}} &NBSP;ELSE&NBSP;{SYSTEM.OUT.PRINTLN ("current cursor for null!!!!!");}}  catch  (exception e)  {system.out.println ("Query stored procedure error:" +e.getcause (). GetMessage ());}  finally {dbconnectionmanager.getinstance (). Freeconnection (Ins.getcus (), userConn);} Return l;} Description: Originally this code is not difficult, mainly to waste time on the registration parameters and read the data on the piece.


Java read Oracle stored procedure return cursor (CURSOR) format read to list

Related Article

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.