Invoking an Oracle stored procedure in Java

Source: Internet
Author: User

Invoking an Oracle stored procedure in Java

This article describes how to invoke Oracle's stored procedures through Java
1. Writing Stored Procedures

CREATEORPROCEDURE  sp_pro3(sp_name VARCHAR2,sp_sal NUMBER )ISBEGIN  --根据用户名修改工资  UPDATE emp SET sal=sp_sal WHERE ename=sp_name;END;
    1. Introduce Jdbc6.jar, write test class Test.java
 PackageTestoraclepro;ImportJava.sql.CallableStatement;ImportJava.sql.Connection;ImportJava.sql.DriverManager; Public  class Test {     Public Static void Main(string[] args) {Try{//1. Load DriverClass.forName ("Oracle.jdbc.driver.OracleDriver");//2. Getting a connectionConnection Ct=drivermanager.getconnection ("Jdbc:oracle:thin:@127.0.0.1:1521:xe","sys as SYSDBA","123456");//3. Creating CallableStatementCallableStatement Cs=ct.preparecall ("{call Sp_pro3 (?,?)}");//4. Assigning ValuesCs.setstring (1,"Zxs"); Cs.setfloat (2,455f);//5. ExecutionCs.execute ();//6. Closing ResourcesCs.close ();        Ct.close (); }Catch(Exception e)        {E.printstacktrace (); }    }}

Execute the above test class to invoke the stored procedure and execute the corresponding program.

Invoking an Oracle stored procedure in Java

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.