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

问题描述 投票:0回答:1
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 ;

我的代码有什么问题?我尝试运行多次。

mysql jdbc
1个回答
0
投票

当用户对数据库架构的权限设置不正确时,我遇到了此错误。

© www.soinside.com 2019 - 2024. All rights reserved.