Reputation: 1
I created a stored procedure as follows:
//Stored procedures in mysql
DELIMITER $$
CREATE PROCEDURE `bank`.`hello` (in id varchar(20),in pass varchar(20))
BEGIN
insert into admin(username,password) values (id,pass);
END $$
DELIMITER ;
and I am calling the stored procedure in java as follows:
//calling stored procedures using JDBC
package StoredProcEx;
import java.sql.*;
public class StoredProcEx {
public static void main(String arg[]){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bank","root","root");
//PreparedStatement stmt=con.prepareStatement("insert into admin values(?,?)");
CallableStatement stmt=con.prepareCall("{?=call hello(?,?)}");
stmt.setString(1,"birender");
stmt.setString(2,"admin");
stmt.execute();
//stmt.execute();
}
catch(ClassNotFoundException ce){
ce.printStackTrace();
}
catch(SQLException se){
se.printStackTrace();
}
catch(Exception e){}
}
}
But it is showing a compile time exception as follows:
Can's set IN parameter for return value of stored function call.
Upvotes: 0
Views: 1199
Reputation: 248
Please use
CallableStatement stmt=con.prepareCall("{call hello(?,?)}");
instead of
CallableStatement stmt=con.prepareCall("{?=call hello(?,?)}");
First ? in your code is used for return type
Upvotes: 3