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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.