hjava.sql.SQLException参数索引20超出范围(1,0)

时间:2017-07-12 11:02:52

标签: javascript java stored-procedures

在调用下面的存储过程时出现En错误。存储过程是用MySQL编写的,调用是从我的计算机到MySQL服务器完成的。

//this is my code to call the procedure
try {
    CallableStatement cStmt =  con.prepareCall("{call beta.Pr_branch_master(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); // my procedure name

    cStmt.setString(1,"N");
    cStmt.setString(2, tranDate);
    cStmt.setInt(3,0);
    cStmt.setString(4, branchStartDt);
    cStmt.setInt(5, Integer.parseInt(orgMstID));
    // cStmt.setInt(4,Types.INTEGER);
    cStmt.setString(6, brType);
    cStmt.setString(7, branchName);
    cStmt.setString(8, address);
    cStmt.setString(9, area);
    cStmt.setString(10, city);
    cStmt.setString(11, state); // these are my parameters to be inserted into the table 
    cStmt.setString(12, pinCode);
    cStmt.setString(13, phoneNo);
    cStmt.setString(14, mobileNo);
    cStmt.setString(15, emailID);
    cStmt.setString(16, regCode);
    cStmt.setString(17, activeFlag);
    cStmt.setInt(18, 1);
    cStmt.setString(19, enterDesc);
    // cStmt.registerOutParameter(19,Types.INTEGER);
    // cStmt.setString(19,branchMstID);
    // cStmt.setInt(19, 0);
    System.out.println("cstmt before out>>>>"+cStmt);
    cStmt.registerOutParameter(20, Types.INTEGER);

    boolean b = cStmt.execute();// executing the statement
    System.out.println("b "+b+"   :"+cStmt);
    primaryKey = cStmt.getInt(20);
    System.out.println("str "+primaryKey);

    if(primaryKey > 0 ){
        /*dbResult = "success";
        result.setStatus(dbResult);*/
        result.setMsg("Record Save Successfully.");
    } else {
        /*dbResult = "error";
        result.setStatus(dbResult);*/
        result.setMsg("Record Not Save.");
    }
} catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
return result;

// I'm getting an error message while calling the stored procedure

1 个答案:

答案 0 :(得分:0)

我的sql连接器jar文件不兼容。以前使用5.01现在使用5.12