public int CalableStatement(String query,Login login,String type) throws ClassNotFoundException, SQLException
{ int i =0;
try {
Connection con = getConnection();
//String q = query+"(?,?,?)";
CallableStatement cst = con.prepareCall("call loginPlan_k(?,?,@result)");
//Login login = null ;
//String type=lassType.getType();
/*if(type.equals("login"))
{
login = (Login)o;
}*/
System.out.println(login.getUserName()+"DataAccess");
cst.setString(1, login.getUserName());
cst.setString(2, login.getPassword());
cst.registerOutParameter(3,java.sql.Types.INTEGER);
ResultSet rs = cst.executeQuery(query);
i = cst.getInt(1); yyy
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return i ;
}
java.lang.ArrayIndexOutOfBoundsException: 20outputfromdb
status0
at com.mysql.jdbc.CallableStatement.checkIsOutputParam(CallableStatement.java:680)
at com.mysql.jdbc.CallableStatement.registerOutParameter(CallableStatement.java:2015)
at Plan__K_Utilities.DataBaseAccess.CalableStatement(DataBaseAccess.java:72)
at PLan__K_MYSQL_DAL.LoginClass.Authenticate(LoginClass.java:22)
at ServletPackage.Login.doPost(Login.java:49)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
我試圖CallableStatement的程序在數據庫執行罰款,但 arrayindex出界錯誤的SQL工具類,是我讓我嘗試調試它似乎有些不妥CallableStatement的的CallableStatement arrayindexoutofbound
的語法public int CalableStatement(String query,Login login,String type) throws ClassNotFoundException, SQLException
{ int i =0;
try {
Connection con = getConnection();
//String q = query+"(?,?,?)";
CallableStatement cst = con.prepareCall("call loginPlan_k(?,?,?)");
//Login login = null ;
//String type=lassType.getType();
/*if(type.equals("login"))
{
login = (Login)o;
}*/
System.out.println(login.getUserName()+"DataAccess");
cst.setString(1, login.getUserName());
cst.setString(2, login.getPassword());
cst.registerOutParameter(3,java.sql.Types.INTEGER);
ResultSet rs = cst.executeQuery(query);
if(rs.next())
{ i = cst.getInt(1);}
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return i ;
}
}
這是錯誤,我收到
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?,?,?)' at line 1
0outputfromdb
status0
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2617)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2819)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2768)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1612)
at Plan__K_Utilities.DataBaseAccess.CalableStatement(DataBaseAccess.java:74)
at PLan__K_MYSQL_DAL.LoginClass.Authenticate(LoginClass.java:22)
at ServletPackage.Login.doPost(Login.java:49)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
我已經做到了,但錯誤盛行 –
你錯過CS括號括
CallableStatements
。嘗試以上... – Reimeus