Invoking Stored Procedures - Java JDBC

Java examples for JDBC:Stored Procedure

Introduction

Suppose we have the following PL/SQL stored procedure.

create or replace procedure my_proc (text IN VARCHAR2,msg OUT VARCHAR2) as 
begin 
    msg :=text; 
end; 

CallableStatement executes this stored procedure.

The results of the OUT parameter are displayed back to the user.

try(CallableStatement cs = conn.prepareCall("{call MY_PROC(?,?)}");) {        
    cs.setString(1, "This is a test"); 
    cs.registerOutParameter(2, Types.VARCHAR); 
    cs.executeQuery(); 

    System.out.println(cs.getString(2)); 

} catch (SQLException ex){ 
    ex.printStackTrace(); 
}

Related Tutorials