我尝试调用具有参数
的存储过程我的代码是:
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)