ArrayIndexOutOfBoundsException when executing StoredProcedure in java
<p>I try to call a stored procedure that have out parameters</p>

<p>My code is:</p>

<pre><code>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);
</code></pre>

<p>but when it execute the line </p>

<pre><code>callableStatement.executeUpdate();
</code></pre>

<p>It throws the error java.lang.ArrayIndexOutOfBoundsException: -1</p>

<p>I was searching in different web pages to solve this problem, but I found by myself that changing the database connection from:</p>

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

<p>to:</p>

<pre><code>DriverManager.registerDriver(new com.mysql.jdbc.Driver());
conn    =   DriverManager.getConnection(DB_CONNECTION, DB_USER,DB_PASSWORD);
</code></pre>

<p>solve the problem, now I want to create a pool connection in tomcat so I change the connection to :</p>

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

<p>but again it throws the same error, can anyone know why this is happening?</p>

<p>Thanks in advance.</p>

<p><strong>EDIT</strong></p>

<p>This is the error:</p>

<pre><code>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)
</code></pre>