Oracle有返回值的存储过程

创建一个有输入输出的存储过程:

<span style="font-size:18px;">CREATE OR REPLACE PROCEDURE sp_pro8
(spno IN NUMBER,spName OUT  VARCHAR2)
IS
BEGIN
    SELECT ename INTO spName FROM emp WHERE empno=spno;
END;</span>


Java代码:

package com.wfc.test;

import java.sql.*;  
public class Test2{  
    public static void main(String[] args){  
    	Connection ct=null;  
    	CallableStatement cs=null;
    	
        try{  
            Class.forName("oracle.jdbc.driver.OracleDriver");  

            ct = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");  
  

            cs = ct.prepareCall("{call sp_pro8(?,?)}");                           //("{call聽sp_pro8(?,?)}");

            cs.setInt(1,7788); 

            cs.registerOutParameter(2,oracle.jdbc.OracleTypes.VARCHAR);
              
        
              
            //5.鎵ц  
            cs.execute();  

            String name=cs.getString(2);
            System.out.println("7788的名字"+name);
            
            
        } catch(Exception e){  
            e.printStackTrace();  
        } finally{  
            //6.鍏抽棴鍚勪釜鎵撳紑鐨勮祫婧� 
            try {
				cs.close();
				ct.close(); 
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}  
             
        }  
    }  
}  

 


你可能感兴趣的:(存储过程,存储过程得返回值)