Java calls Oracle procedures return result sets (packages and cursors) ____oracle

Source: Internet
Author: User

1, process definition (package, cursor, process)

------------The top return is a record, but returns more than one record to use the following--------------------
--1: The process of returning a result set, in which the Test_cursor cursor
is defined The Create or replace package testpackage as
type test_cursor is ref cursor;--defines a test_cursor end
testpackage;
--2: Creating process Create
or replace procedure sp_pro13
(Spno in Number,p_cursor out testpackage.test_cursor)
is Begin 
  Open P_cursor for SELECT * from EMP where deptno=spno;
End;   
--3: in Java when calling


2,java-End Calls

	Class.forName (driver);
			Conn=drivermanager.getconnection (strURL, "Scott", "Tiger");
			CallableStatement Pro =conn.preparecall ("{Call Sp_pro13 (?,?)}");
			Pro.setint (1);
			There is a cursor variable
			pro.registeroutparameter (2, Oracle.jdbc.OracleTypes.CURSOR);
			Pro.execute ();
			ResultSet rset= (ResultSet) Pro.getobject (2);
			while (Rset.next ()) {
				System.out.println (rset.getstring (8) + "--->" +rset.getstring (1) + "--->" + Rset.getstring (2));			}
			Rset.close ();
			Pro.close ();
			Conn.close ();


3 results:

--->7499--->allen
--->7521--->ward
--->7654--->martin
--->7698--- >blake
--->7844--->turner
--->7900--->james


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.