-1
     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)

私はSQLユーティリティクラスのCallableStatementを試していましたプロシージャはDBで正常に実行されていますが、配列インデックスの範囲外エラーが発生しましたデバッグしようとしましたが、callablestatementの構文に何か問題があるようです

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)
4

2 に答える 2