Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6831025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:41:18+00:00 2026-05-26T22:41:18+00:00

In a previous piece of code I received the exact same error I listed

  • 0

In a previous piece of code I received the exact same error I listed in the title.

I had a username validator in my code but forgot to include the following code:

password =ESAPI.validator().getValidInput("Login password", password, "Password", 20, false);

After adding that I resolved the issue.

Now in my next java page I have run into the same problem and reviewed the code and have not been able to find what I am missing, if I am in fact missing something.

I had this same error with another piece of code I was working on and was able to resolve it as I had forgot to include another line of code.

For this piece of code however I have gone over it several times and cannot figure what is wrong with it.

Here is the code:

    package com.tunestore.action;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.util.MessageResources;
import org.owasp.esapi.ESAPI;

import com.tunestore.util.IWithDataSource;

public class RegisterAction extends Action implements IWithDataSource {
  private DataSource dataSource;

  public void setDataSource(DataSource dataSource) {
    this.dataSource = dataSource;
  }

  public ActionForward execute(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    DynaActionForm daf = (DynaActionForm)form;
    ActionMessages errors = new ActionMessages();
    ActionForward forward = mapping.getInputForward();
    MessageResources resources = getResources(request);


    //ESAPI START
    if (!ESAPI.validator().isValidInput("Register username", daf.getString("username"), "SafeString", 20, false)) {
    //ESAPI END


      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.required", resources.getMessage("prompt.username")));
    }


    //ESAPI START
    if (!ESAPI.validator().isValidInput("Register password", daf.getString("password"), "password", 20, false)) {
    //ESAPI END


      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.required", resources.getMessage("prompt.password")));
    }


    //ESAPI START
    if (!ESAPI.validator().isValidInput("Register confirm password", daf.getString("rptpass"), "password", 20, false)) {
    //ESAPI END 


      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.required", resources.getMessage("prompt.rpt")));
    }
    if ((null != daf.getString("password")) && (null != daf.getString("rptpass"))) {
      if (! daf.getString("password").equals(daf.getString("rptpass"))) {
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.rptpass.nomatch"));
      }
    }

    Connection conn = null;
    try {
      conn = dataSource.getConnection();
      Statement stmt = conn.createStatement();
      ResultSet rs = stmt.executeQuery("SELECT COUNT(*) USERCNT "
          + "FROM TUNEUSER "
          + "WHERE USERNAME = '"
          + daf.getString("username")
          + "'");
      rs.next();
      if (rs.getInt("USERCNT") > 0) {
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.exists"));
      } else if (errors.isEmpty()) {



          //ESAPI START
          String sql = "INSERT INTO TUNEUSER (USERNAME,PASSWORD,BALANCE) VALUES (?, ?, ?)";
          PreparedStatement pStmt = conn.prepareStatement(sql);
          pStmt.setString(0, daf.getString("username"));
          pStmt.setString(1, daf.getString("password"));
          pStmt.setDouble(2, 0.00);
          pStmt.executeUpdate();
          //ESAPI END



        ActionMessages msgs = getMessages(request);
        msgs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("user.added"));
        forward = mapping.findForward("success");
      }
    } catch (Exception e) {
      e.printStackTrace();
      throw e;
    } finally {
      if (conn != null) {
        try { conn.close(); } catch (Exception e) {}
      }
    }

    request.setAttribute("ERRORS.REGISTER", errors);
    return forward;
  }
}

The code is for a registration form. When someone tries to register though the following error is given in return.

    java.sql.SQLException: The column position '0' is out of range.  The number of columns for this ResultSet is '3'.
    at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
    at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
    at org.apache.derby.client.am.ColumnMetaData.getColumnType(Unknown Source)
    at org.apache.derby.client.am.PreparedStatement.setString(Unknown Source)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.setString(DelegatingPreparedStatement.java:132)
    at com.tunestore.action.RegisterAction.execute(RegisterAction.java:90)
    at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
    at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
    at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
    at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
    at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
    at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.tunestore.servlet.PersistenceFilter.doFilter(PersistenceFilter.java:77)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:244)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:558)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:379)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:259)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:281)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.derby.client.am.SqlException: The column position '0' is out of range.  The number of columns for this ResultSet is '3'.
    at org.apache.derby.client.am.ColumnMetaData.checkForValidColumnIndex(Unknown Source)
    ... 34 more



ROOT CAUSE
org.apache.derby.client.am.SqlException: The column position '0' is out of range.  The number of columns for this ResultSet is '3'.
    at org.apache.derby.client.am.ColumnMetaData.checkForValidColumnIndex(Unknown Source)
    at org.apache.derby.client.am.ColumnMetaData.getColumnType(Unknown Source)
    at org.apache.derby.client.am.PreparedStatement.setString(Unknown Source)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.setString(DelegatingPreparedStatement.java:132)
    at com.tunestore.action.RegisterAction.execute(RegisterAction.java:90)
    at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
    at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
    at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
    at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
    at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
    at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.tunestore.servlet.PersistenceFilter.doFilter(PersistenceFilter.java:77)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:244)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:558)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:379)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:259)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:281)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

The error appears to be pointing to line 90 of my code which is:

pStmt.setString(0, daf.getString("username"));

Yet this line of code looks correct to me. What could I be missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:41:19+00:00Added an answer on May 26, 2026 at 10:41 pm

    Column indexes start at 1 in JDBC

    I can’t see you calling setString in the code, but the stack trace clearly says execute is calling setString at line #90. Is the code you posted exactly what’s running when you get this exception?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently this piece of code for creating a UISearchBar (adapted from a previous
I have a very simple piece of code that I used in previous versions
We had a piece of code in C in one class where we needed
This is connected with my previous question as it's dealt with the same piece
I'm not sure how to explain this but this piece of code bellow can
Here is a piece of code: #include <stdio.h> #include <stdarg.h> void MyPrintf(char const* format,
This piece of code works as I want it to, but in the spirit
From previous experience I had been under the impression that it's perfectly legal (though
In previous question of mine, someone had meantioned that using Semaphores were expensive in
Thanks @dtb for help, he advised really need piece of code for generic service

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.