在java中执行StoredProcedure时出现ArrayIndexOutOfBoundsException

时间:2016-05-11 20:44:28

标签: java mysql

我尝试调用具有参数

的存储过程

我的代码是:

CallableStatement callableStatement = conn.prepareCall("{CALL banco.sppro_prepagoprestamo(?,?,?,?,NOW(),?,?)}");
callableStatement.registerOutParameter(1, Types.VARCHAR);
callableStatement.registerOutParameter(2, Types.INTEGER);
callableStatement.setString(3,cuenta);
callableStatement.setString(4,monto);
callableStatement.setString(5,usuarioIdLog);
callableStatement.setString(6,tipoPago);
callableStatement.executeUpdate();
String msg = callableStatement.getString(1);
int codigo = callableStatement.getInt(2);

但是当它执行行

callableStatement.executeUpdate();

抛出错误java.lang.ArrayIndexOutOfBoundsException:-1

我在不同的网页上搜索来解决这个问题,但我自己发现改变了数据库连接:

DriverManager.registerDriver(new com.mysql.jdbc.Driver());
conn    =   DriverManager.getConnection("jdbc:mysql://localhost:3306/banco?user=user&password=pass");

为:

DriverManager.registerDriver(new com.mysql.jdbc.Driver());
conn    =   DriverManager.getConnection(DB_CONNECTION, DB_USER,DB_PASSWORD);

解决问题,现在我想在tomcat中创建一个池连接,所以我将连接更改为:

InitialContext context = new InitialContext();
DataSource dataSource = (DataSource) context.lookup("java:comp/env/jdbc/BancoDB");
conn= dataSource.getConnection();

但是它又引发了同样的错误,有人知道为什么会这样吗?

提前致谢。

修改

这是错误:

java.lang.ArrayIndexOutOfBoundsException: -1
    com.mysql.jdbc.CallableStatement.setOutParams(CallableStatement.java:2088)
    com.mysql.jdbc.CallableStatement.executeUpdate(CallableStatement.java:822)
    org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
    org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
    org.apache.jsp.credito.procesos.creproprepagoprestarjeta.creProPrepagoCtaVirtualGraba_jsp._jspService(creProPrepagoCtaVirtualGraba_jsp.java:1455)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

1 个答案:

答案 0 :(得分:1)

这是mysql驱动程序中的已知问题,已在5.1.13详细信息here中修复,因此要修复错误,只需将其升级到最新版本。