日期:2014-05-17  浏览次数:20749 次

调用MYSQL存储过程引发的“Parameter index of 5 is out of range (1, 4)”问题
错误信息如下:

0:13:58,218  INFO SbxxServiceImpl:19 - 开始执行SbxxServiceImpl类的 createSblx 方法 !
10:13:58,218  INFO SbxxDaoImpl:24 - 开始执行SbxxDaoImpl类的 createSblx 方法 !
10:13:58,218  INFO SbxxDaoImpl:32 -  执行新增设备类型操作 方法 ,调用存储过程 : call ps_ddgl_sblx_insert(yyyy ,yyy ,yyyyy,3,0) ;
10:13:58,218 ERROR SbxxDaoImpl:47 -  执行新增设备类型操作出错了,导致原因可能是:< Parameter index of 5 is out of range (1, 4)> 
10:13:58,218 ERROR SbxxDaoImpl:50 - com.mysql.jdbc.CallableStatement.checkParameterIndexBounds(CallableStatement.java:1002)
10:13:58,218 ERROR SbxxDaoImpl:50 - com.mysql.jdbc.CallableStatement.checkIsOutputParam(CallableStatement.java:971)
10:13:58,218 ERROR SbxxDaoImpl:50 - com.mysql.jdbc.CallableStatement.registerOutParameter(CallableStatement.java:864)
10:13:58,218 ERROR SbxxDaoImpl:50 - org.apache.commons.dbcp.DelegatingCallableStatement.registerOutParameter(DelegatingCallableStatement.java:95)
10:13:58,218 ERROR SbxxDaoImpl:50 - org.apache.commons.dbcp.DelegatingCallableStatement.registerOutParameter(DelegatingCallableStatement.java:95)
10:13:58,218 ERROR SbxxDaoImpl:50 - com.zichen.zhhwd.sbxx.dao.impl.SbxxDaoImpl.createSblx(SbxxDaoImpl.java:39)
10:13:58,218 ERROR SbxxDaoImpl:50 - com.zichen.zhhwd.sbxx.service.impl.SbxxServiceImpl.createSblx(SbxxServiceImpl.java:20)
10:13:58,218 ERROR SbxxDaoImpl:50 - com.zichen.zhhwd.action.sbxx.SblxAction.doaddsblx(SblxAction.java:68)
10:13:58,218 ERROR SbxxDaoImpl:50 - sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
10:13:58,234 ERROR SbxxDaoImpl:50 - sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
10:13:58,234 ERROR SbxxDaoImpl:50 - sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
10:13:58,234 ERROR SbxxDaoImpl:50 - java.lang.reflect.Method.invoke(Method.java:597)


存储过程源码 :

CREATE  
PROCEDURE  ps_ddgl_sblx_insert(IN ps_lxmc VARCHAR(20)  CHARACTER SET UTF8, IN ps_lxjx VARCHAR(3) CHARACTER SET UTF8, IN ps_lxbz VARCHAR(50) CHARACTER SET UTF8, IN ps_ggwsx int(11),OUT exceResult INT)
  COMMENT '新增设备类型'
BEGIN
   DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK;
  SET exceResult =0;
  START TRANSACTION;

    select  count(*) into @likeset   from   ddgl_sblx  where   lxmc = ps_lxmc   or  lxjx=  ps_lxjx ;
  if (@likeset >0) then
     SET exceResult = 2;
 else
   INSERT INTO ddgl_sblx ( lxmc, lxjx, lxbz,ggwsx) VALUES (ps_lxmc, ps_lxjx, ps_lxbz,ps_ggwsx);
  COMMIT;
  SET exceResult = 1;
end if  ;
END


java 程序代码 :

Logger log = Logger.getLogger(SbxxDaoImpl.class);

public int cr