Oracle Java source returns the dataset (1)

Source: Internet
Author: User
Java calls the Oracle function to return the result set Time:2010-08-27 10:19:50 Source:Network Author:Unknown Click:Create or replace package my_steel_soft 208 times
As
-- Type of the dataset returned by the Stored Procedure
Type returndataset is ref cursor;

Create or replace package my_steel_soft
As
-- Type of the dataset returned by the Stored Procedure
Type returndataset is ref cursor;

End my_steel_soft;

Create or replace function BB (begindate in varchar2)
Return my_steel_soft.returndataset
As
Acursor my_steel_soft.returndataset;
Begin
Open acursor for select * From v_out_orderqry t
Where T. dorderdate> = begindate;
-- And T. dorderdate <enddate;
-- And T. ssalerguid = orgguid
-- Or T. sbuyguid = orgguid;
Return acursor;
End BB;

/**
* Testfun. Java
* Create on 2007-5-23
* Copyright 2010 mysteelsoft All Rights Reserved.
*/
Package com. test;

Import java. SQL. callablestatement;
Import java. SQL. connection;
Import java. SQL. drivermanager;
Import java. SQL. resultset;
Import java. SQL. sqlexception;
Public class testfun {
 
Public static void main (string [] ARGs)
{

Connection connection = NULL;
Try {
Class. forname ("oracle. JDBC. Driver. oracledriver ");
}
Catch (classnotfoundexception e ){
System. Out. println ("database driver class not found ");
}
Try {
Resultset rs = NULL;
String servername = "192.168.18.21 ";
String portnumber = "1521 ";
String SID = "eTrade ";
String url = "JDBC: oracle: thin: @" + servername + ":" + portnumber + ":" + Sid;
String username = "Developer ";
String Password = "mysteelsoft ";
Connection = drivermanager. getconnection (URL, username, password );
Callablestatement cstmt = NULL ;;
Cstmt = connection. preparecall ("{? = Call BB (?)} ");

// Cstmt = connection. preparecall ("? = Call eTrade. BB (?); ");
Cstmt. registeroutparameter (1, Oracle. JDBC. oracletypes. cursor );
Cstmt. setstring (2, "2006-12-12 ");
System. Out. println (cstmt );
Cstmt.exe cute ();
Rs = (resultset) cstmt. GetObject (1 );
If (RS! = NULL ){
While (Rs. Next ()){
System. Out. Print (Rs. getstring (1) + "");
System. Out. Print (Rs. getstring (2) + "");
System. Out. println (Rs. getstring (3 ));
}
}
Cstmt. Close ();
Connection. Close ();
} Catch (sqlexception e ){
E. printstacktrace ();
}
}
}
 

/**
* Testfun. Java
* Create on 2007-5-23
* Copyright 2010 mysteelsoft All Rights Reserved.
*/
Package com. test;

Import java. SQL. callablestatement;
Import java. SQL. connection;
Import java. SQL. drivermanager;
Import java. SQL. resultset;
Import java. SQL. sqlexception;

Import javax. SQL. rowset. cachedrowset;

Import com. Sun. rowset. cachedrowsetimpl;
Public class testfun {
 
Public static void main (string [] ARGs)
{

Connection connection = NULL;
Try {
Class. forname ("oracle. JDBC. Driver. oracledriver ");
}
Catch (classnotfoundexception e ){
System. Out. println ("database driver class not found ");
}
Try {
Cachedrowset CRS = new cachedrowsetimpl ();

Resultset rs = NULL;
String servername = "192.168.18.21 ";
String portnumber = "1521 ";
String SID = "eTrade ";
String url = "JDBC: oracle: thin: @" + servername + ":" + portnumber + ":" + Sid;
String username = "Developer ";
String Password = "mysteelsoft ";
Connection = drivermanager. getconnection (URL, username, password );
Callablestatement cstmt = NULL ;;
Cstmt = connection. preparecall ("{? = Call BB (?)} ");

Cstmt. registeroutparameter (1, Oracle. JDBC. oracletypes. cursor );
Cstmt. setstring (2, "2006-12-12 ");
Cstmt.exe cute ();
System. Out. println (cstmt );
Rs = (resultset) cstmt. GetObject (1 );
CRS. populate (RS );

If (CRS! = NULL ){
While (CRS. Next ()){
System. Out. Print (CRS. getstring ("sguid") + "");
System. Out. Print (CRS. getstring ("sorderid") + "");
System. Out. println (CRS. getstring ("ssalerguid "));
}
}
Cstmt. Close ();
Connection. Close ();
} Catch (sqlexception e ){
E. printstacktrace ();
}
}
}

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.