Bug #55328 outParameter (8, Type.VARCHAR)
Submitted: 16 Jul 2010 21:53 Modified: 3 Apr 2013 1:43
Reporter: Raphael Quadrini Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:5.1.13 OS:Linux (Slackware 13.1 64b)
Assigned to: Alexander Soklakov CPU Architecture:Any

[16 Jul 2010 21:53] Raphael Quadrini
Description:
This code does work with the JDBC V 5.1.13 while working with V 5.1.10

Exception message is : parameter index of 8 is out of range (1,0)

   String sp = "{CALL `SP_MYPROC`(?,?,?,?,?,?,?,?)}";
        try {
            conn = this.getConn();
            stmt = conn.prepareCall(sp);
            stmt.setString(1, this.action);
            stmt.setString(2, this.getTid());
            stmt.setInt(3, this.getLid(0));
            stmt.setInt(4, this.getEid(0));
            stmt.setString(5, this.getLabel());
            stmt.setString(6, this.getNomobjet());
            stmt.setString(7, this.getDatmodif());
            stmt.registerOutParameter(8, Types.LONGVARCHAR);
            isRs = stmt.execute();
            this.setErrmsg(stmt.getString(8));
            if (isRs) {
                rs = stmt.getResultSet();
                if (rs != null) {
                    rs.close();
                    rs = null;
                }
            }
            stmt.close();
            stmt = null;
            conn.close();
            conn = null;
        } catch (Exception e) {
            this.setErrmsg(e.getMessage());
        }

From the mysql console the call of the stored proc works fine.

from the java console maybe this trace can help :

ul 16, 2010 10:21:36 AM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
        at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2502)
        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2952)
        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2941)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3489)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2113)
        at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2275)
        at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
        at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doEndTag(QueryTagSupport.java:215)
        at org.apache.jsp.login_jsp._jspx_meth_sql_005fquery_005f1(login_jsp.java:814)
        at org.apache.jsp.login_jsp._jspx_meth_c_005fotherwise_005f0(login_jsp.java:728)
        at org.apache.jsp.login_jsp._jspx_meth_c_005fchoose_005f0(login_jsp.java:124)
        at org.apache.jsp.login_jsp._jspService(login_jsp.java:94)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
        at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:408)
        at com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:442)
        at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:115)
        at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
        at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
        at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Thread.java:619)

How to repeat:
Create a simple stored proc with 2 paramters like the following code

Create sp_myproc(t in varchar(255), v out varchar(255))
begin
set v=t;
end//

do a call of sp_myproc from a java prog. you should get the same error message.

Suggested fix:
look at V5.1.10 which is working fine and copy paste the piece of code.
[30 Aug 2010 9:37] Tonci Grgin
Raphael, I have found an error in responsible part of code... Patch is waiting for review before it's pushed.
[13 Sep 2010 8:15] Tonci Grgin
Raphael, please try with latest snapshot from http://downloads.mysql.com/snapshots.php and reopen the bug report if you still have troubles.
[13 Oct 2010 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[29 Mar 2013 8:13] Alexander Soklakov
It looks like fix was pushed to 5.1.14 and I can't reproduce the failure with latest version.

So I'll close this report as fixed. But, since I didn't find the exact patched revision, feel free to reopen it if you find the  problem still exists.
[3 Apr 2013 1:43] Paul DuBois
Noted in 5.1.14 changelog.

Connector/J could exit wth a "parameter index out of range" error
when executing stored procedures.