Execute SQL Function CallableStatement JDBC

Execute SQL Function CallableStatement JDBC


In the following program a function by name calculate() is executed from JDBC. The function includes one IN parameter, one OUT parameter and one return value (note that return value can be one only, but IN and INOUT can be of any number).

CallableStatement along with PreparedStatement is fully discussed in Difference between Statement, PreparedStatement, CallableStatement.

Example on Execute SQL Function CallableStatement JDBC

See this function exists in the database before the JDBC program is executed.


Execute SQL Function CallableStatement JDBC
Output screenshot on Execute SQL Function CallableStatement JDBC

CallableStatement cst=con.prepareCall(“{ ? = call calculate(?,?) }”);

1st question mark is return value, the 2nd question mark represents IN parameter, and the 3rd question mark is for OUT parameter. Both OUT and return values should be registered with CallableStatement using registerOutParameter() method.

A program exists for executing stored procedure at Executing stored procedure with CallableStatement Interface.

Note: If the JDBC basics are not clear, it is advised to go through JDBC Programming Basic Steps where the meaning of Connection, Statement etc. are discussed.

Note: To know how to use try-catch-finally with the above code, example program is available at JDBC Example – Create Table.

2 thoughts on “Execute SQL Function CallableStatement JDBC

Leave a Reply

Your email address will not be published. Required fields are marked *