java.sql.SQLException:参数编号3不是OUT参数

时间:2017-07-02 10:27:28

标签: mysql jdbc

package dbConnection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Types;

import com.mysql.jdbc.CallableStatement;

public class MysqlConTest {

    public static void main(String args[]) {
        try {
            System.out.println("Welcome");
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            Connection con=DriverManager.getConnection(  
                    "jdbc:mysql://localhost:3306","root","abc1234");  
            // here DeliGo is database name, root is username and password
            CallableStatement cStmt = (CallableStatement) con.prepareCall("{call checkIf_merchant_exists(?, ?, ?)}");
            cStmt.setString(1, "neha");
            cStmt.setString(2, "901");
            System.out.println("Hello 1 -------");
            cStmt.registerOutParameter(3, Types.CHAR);
            System.out.println("Hello 2 -------");
            boolean hadResults = cStmt.execute();
            System.out.println("Had Results------" + hadResults);

            String test = cStmt.getString(3);

            System.out.println("-----------Exists = "+test);

            con.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    }

}

我正在尝试连接到My SQL并获取:

  

java.sql.SQLException:参数编号3不是OUT参数。

相应的My SQL过程是

DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `checkIf_merchant_exists`(IN p_user_nm varchar(45),
IN p_mobile_num int(11),
OUT p_exists char)
BEGIN

declare total_count int default 0;

Select count(*) into total_count from mydb.merchant_details md
where upper(md.user_nm) = upper(p_user_nm)
and md.mobile_num = p_mobile_num;

    IF total_count > 0
        then set p_exists = 'Y';
    else
        set p_exists = 'N';
    end if;

   END$$
DELIMITER ;

我的代码出了什么问题?我试过多次运行它。

0 个答案:

没有答案