Java calls a stored procedure in Oracle

Source: Internet
Author: User

-- Build Tables sql> CREATE TABLE Tbook (bookId number (8), BookName varchar2 (50), Publishhouse VARCHAR2 (());  -- writing process -in: input parameters;  Begin  INSERT INTO Tbook values (spbookid,spname,sppublishhost); end;
--Called in Java (Odbcdriver to be loaded in the project)
1  PackageOracle;2 3 Importjava.sql.CallableStatement;4 Importjava.sql.Connection;5 ImportJava.sql.DriverManager;6 Importjava.sql.SQLException;7 8 9 Ten //call a procedure with no return value One  Public classTest01 { A  -      Public Static voidMain (string[] args) { -         //TODO auto-generated Method Stub theConnection conn =NULL; -CallableStatement cs =NULL; -         Try { -             //1. Load Driver +Class.forName ("Oracle.jdbc.driver.OracleDriver"); -              +             //2. Connect AString url = "jdbc:oracle:thin:@127.0.0.1:1521:oracle12c"; atString userName = "sys as SYSDBA"; -String password = "fairy6280"; -conn =drivermanager.getconnection (Url,username,password); -             //3. Create CallableStatement -String sql = "{call Sp_pro7 (?,?,?)}"; -CS =conn.preparecall (SQL); in             //give '? ' Assign Value -Cs.setint (1, 1001); toCs.setstring (2, "The History of the Three Kingdoms"); +Cs.setstring (3, "People ' s publishing house"); -             //Execution the Cs.execute (); *              $}Catch(Exception e) {Panax Notoginseng             //TODO auto-generated Catch block - e.printstacktrace (); the         } +         finally{ A             //Close the             Try { + cs.close (); - conn.close (); $}Catch(SQLException e) { $                 //TODO auto-generated Catch block - e.printstacktrace (); -             } the         } -     }Wuyi  the}

Java calls a stored procedure in Oracle

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.