Simple stored procedures for connecting and calling Oracle databases

Source: Internet
Author: User

Oracle Database Connection and calling of Stored Procedures
Create table chengji (id number, xing_ming varchar2 (25), yu_wen number, shu_xue number)
-- Query All Information select * from chengji
-- Stored procedure with no return value type
Create procedure cj_proc_1 is
Begin
Insert into chengji values (3, 'wangw', 90, 90 );
Commit;
End;
-- Input a stored procedure with a value returned
Create procedure cj_proc_2
(X_name in varchar2, x_num out number) is
Num_1 number; num_2 number;
Begin
Select yu_wen, shu_xue into num_1, num_2 from chengji where xing_ming = x_name; x_num: = num_1 + num_2;
End;
Database connection:
Public static void main (String [] args ){

Connection conn = null;
// Database connection
Try {

Class. forName ("oracle. jdbc. driver. OracleDriver ");
Conn = DriverManager. getConnection ("jdbc: oracle: thin: @ 127.0.0.1: 1521: orcl", "system", "admin ");

} Catch (Exception e ){
E. printStackTrace ();
}
// Operate the database
Try {
CallableStatement proc = null;

Proc = conn. prepareCall ("{call cj_proc_2 (?,?)} ");
Proc. setString (1, "zhangsan ");
Proc. registerOutParameter (2, Types. NUMERIC );

Proc.exe cute ();
String jieguo = proc. getString (2 );
System. out. println ("======================" + jieguo );
Conn. close ();
} Catch (Exception e ){
E. printStackTrace ();
}

}

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.