Java calls Oracle stored procedures return multiple result sets

Source: Internet
Author: User
Package jp.co.kindlingsoft;
Import java.sql.CallableStatement;
Import java.sql.Connection;
Import Java.sql.DriverManager;
Import Java.sql.ResultSet;

Import java.sql.SQLException; public class TestDB {public static void main (string[] args) throws ClassNotFoundException, SQLException {String
		Driver = "Oracle.jdbc.driver.OracleDriver";
		String url = "Jdbc:oracle:thin: @localhost: 1521:kin";
		String user = "KIN";

		String password = "KIN";
		Connection con = null;
		CallableStatement stmt = null;

		ResultSet rs = null;

		Class.forName (driver);
		con = drivermanager.getconnection (url, user, password);
		stmt = Con.preparecall ("{Call Get_data (?,?)}");
		Stmt.registeroutparameter (1, Oracle.jdbc.OracleTypes.CURSOR);
		Stmt.registeroutparameter (2, Oracle.jdbc.OracleTypes.CURSOR);

		Stmt.execute ();
		rs = (ResultSet) stmt.getobject (1); while (Rs.next ()) {System.out.println (Rs.getobject (1));//Rs.getobject (column_name)} System.out.println ("******* *****************************************");
		rs = (ResultSet) stmt.getobject (2);
		while (Rs.next ()) {System.out.println (Rs.getobject (1));

 }
	}
}


CREATE OR REPLACE PROCEDURE get_data (
cur_out_1 out Sys_refcursor,
cur_out_2 out sys_refcursor) is

The BEGIN
	OPEN cur_out_1 for 
		SELECT user_tab_cols. column_name from
		user_tab_cols
		WHERE table_name = ' TABLE1 ';
		
	OPEN cur_out_2 for 
		SELECT user_tab_cols. column_name from
		user_tab_cols
		WHERE table_name = ' TABLE2 ';
End Get_data


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.