title: Prepared statement Parameter index out of range (0 < 1 )
body: <p>Am not expert on web application, recently am writing a small webapp for my mobile app using servlets. My agenda is to receive data from client, and to put it into db. everything is running fine except, my database insert statement,which am trying to achieve using PreparedStatement.</p>
  
  <pre><code>// This is how my insert statement looks like
  private String INSERT_INTO_DEVICES = "INSERT INTO travlemate.devices (owner,"
          + "deviceid,gcmid) VALUES (?,?,?)"; 
  
  // This is how am trying to insert
  PreparedStatement preparedStmt = mConn.prepareStatement(INSERT_INTO_DEVICES);
  preparedStmt.setString(0, data.getDeviceNumber());
  preparedStmt.setString(1, data.getDeviceID());
  preparedStmt.setString(2,data.getGcmId());
  preparedStmt.execute();
  mConn.close();
  </code></pre>
  
  <p>but while executing this task, am receiving following exception</p>
  
  <pre><code>java.sql.SQLException: Parameter index out of range (0 &lt; 1 ).
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
      at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:2791)
      at com.mysql.jdbc.PreparedStatement.setString(PreparedStatement.java:3627)
      at com.mkgcorp.travelweb.data.DataManager.registerGCMData(DataManager.java:35)
      at com.mkgcorp.travelweb.controller.Loader.doPost(Loader.java:46)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
      at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
      at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>I seriously tried all sorts of thing which am capable of, but this exception is not going away, any idea on same?</p>
  
  <p>Thanks,
  Techfist</p>