Sunday, 1 November 2020

procedure call with mysql

 https://www.mysqltutorial.org/calling-mysql-stored-procedures-from-jdbc/



Introducing to CallableStatement and stored procedure call syntax

To call stored procedures or stored functions in MySQL from JDBC, you use CallableStatement object, which inherits from PreparedStatement object. The general syntax of calling a stored procedure is as follows:

{?= call procedure_name(param1,param2,...)}

You wrap the stored procedure call within braces ({}). If the stored procedure returns a value, you need to add the question mark and equal (?=) before the call keyword. If a stored procedure does not return any values, you just omit the ?= sign. In case the stored procedure accepts any parameters, you list them within the opening and closing parentheses after the stored procedure’s name.

The following are examples of using the syntax for calling stored procedures in different contexts:

SyntaxStores Procedures
{  call procedure_name() }Accept no parameters and return no value
{ call procedure_name(?,?) }Accept two parameters and return no value
{?= call procedure_name() }Accept no parameter and return value
{?= call procedure_name(?) }Accept one parameter and return value

No comments:

Post a Comment