Oracle uses stored procedures with Input and Output Parameters

Source: Internet
Author: User

Oracle uses a stored procedure with input and output parameters. It is still a bit troublesome to use the stored procedure. If you are not careful about the parameter errors, you are advised to use them less if you can use them less. Here I want to use jdbc to share with you a simple stored procedure I have written myself. I have not studied the framework. In a few days, we will make up for you. 1. first, write a stored procedure with input and output parameters [SQL] create or replace procedure xxx (newfid In Number, newfname Out Varchar) www.2cto.com As begin Select fname Into newfname From m_student Where fid = newfid; end; note that varchar cannot be written As varchar2; otherwise, the input and output parameters do not match. run the stored procedure [java] package org. lxh; import java. SQL. callableStatement; import java. SQL. connection; import java. SQL. resultSet; import java. SQL. SQLException; import or Acle. jdbc. oracleCallableStatement; public class TestUse {public static void main (String [] args) throws Exception {DBConnection con = new DBConnection (); Connection getConn = con. getConnection (); OracleCallableStatement cs = (OracleCallableStatement) getConn. prepareCall ("{call xxx (newfid =>: newfid, newfname =>: newfname)}"); cs. setInt (1,365); www.2cto.com cs. registerOutParameter (2, java. SQL. types. VARCHAR); cs.exe cute (); String strAge = cs. getString (2); System. out. println ("fid is:" + strAge); getConn. close () ;}} OracleCallableStatement can be written as CallableStatement. input parameters do not need to be registered, but output parameters need to be registered. The most important thing to note is the data type. Otherwise, errors may occur.
Author: chenwill3

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.