Java call Stored Procedure example Edition

Source: Internet
Author: User
Tags stored procedure example

Java code:
Package procedure;
 
Import java. SQL. CallableStatement;
Import java. SQL. Connection;
Import java. SQL. DriverManager;
Import java. SQL. ResultSet;
Import java. SQL. SQLException;
Import java. SQL. Statement;
 
Public class TestProcedureOne {
Public TestProcedureOne (){
}
 
Public static void main (String [] args ){
String driver = "oracle. jdbc. driver. OracleDriver ";
// Oracle. jdbc. driver. OracleDriver
String strUrl = // "jdbc. oracle: thin: @ 127.0.0.1: 1521: ORCL ";
"Jdbc: oracle: thin: @ 127.0.0.1: 1521: orcl ";
ResultSet rs = null;
Connection con = null;
Try {
Class. forName (driver );
Con = DriverManager. getConnection (strUrl, "username", "password ");
CallableStatement proc = null;
Proc = con. prepareCall ("{call TESTA (?,?)} ");
Proc. setString (1, "firstName ");
Proc. setString (1, "77.77 ");
Proc.exe cute ();
} Catch (SQLException ex2 ){
Ex2.printStackTrace ();
} Catch (Exception ex2 ){
Ex2.printStackTrace ();
} Finally {
Try {
If (rs! = Null ){
Rs. close ();
If (con! = Null ){
Con. close ();
}
}
} Catch (SQLException ex1 ){
}
}
}
}
Stored Procedure:
Create or replace procedure testa (PARA1 IN VARCHAR2, PARA2 IN VARCHAR2)
BEGIN
Insert into book (Bookname, BOOKPRICE) VALUES (PARA1, PARA2 );
End testa;

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.