帶有傳回值的oracle 預存程序 大 | 中 | 小

來源:互聯網
上載者:User
建立表
create table Atable
(
test1 varchar2(20),
test2 varchar2(20)
);

建立預存程序

create or replace procedure TestD(PARA_1 IN VARCHAR2,PARA_2 OUT VARCHAR2) AS
BEGIN
--SELECT INTO PARA_2 FROM Atable where test1=PARA_1;
select test1 into PARA_2 from Atable where test1=PARA_1;
end TestD;

使用java取得返回結果

package SQl;

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 testStockProcess {

 public static void main(String[] args) {

    Connection connection = null;  
     Connection con;
     Statement  sta;
     ResultSet  rs;
       try{  
              Class.forName("oracle.jdbc.driver.OracleDriver");  
            }  
            catch(ClassNotFoundException  e)  
            {  
              System.out.println("資料庫驅動類沒找到");    
            }    
      try {      
           // 建立串連
           String serverName = "192.168.0.106";
           String portNumber = "1521";
           String sid = "snecma";
           String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
           String username = "sinecma";
           String password = "sinecma123tsuo";
           connection = DriverManager.getConnection(url, username, password);
           System.out.println("資料庫連接成功!");
       }  catch (SQLException e) {
         System.out.println("執行SQL語句異常!");              
              e.printStackTrace();    
       }

       CallableStatement proc = null;

         try {
       proc = connection.prepareCall("{ call RUQProceTest(?)}");
         proc.setString(1, "wdx");
         proc.execute();
     } catch (SQLException e) {

       e.printStackTrace();
     }
 }

}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.