title: Adding J Table content to MySQL database in Java
body: <p>I coded for setting JTable contents to the MySQL database. Invoice no is getting by a text field. Other data is in the J table.</p>
  
  <p>The code is available below;</p>
  
  <pre><code>        String invoice = InvoiceNo_txt.getText(); 
          String id = (String) tableSale.getValueAt(i, 0);
          String name = (String) tableSale.getValueAt(i, 1);
          double dcost =  (double) tableSale.getValueAt(i, 2);
          String cost = String.valueOf(dcost);//converting double to string
          double dqty = (double) tableSale.getValueAt(i, 3);
          String qty = String.valueOf(dqty);//converting double to string
          double ditemDiscount = (double) tableSale.getValueAt(i, 4);
          String itemDiscount = String.valueOf(ditemDiscount);//converting double to string
          double dgrossTotal = (double) tableSale.getValueAt(i, 5);
          String grossTotal = String.valueOf(dgrossTotal);//converting double to string
  
      try{
              String sql2 = "Insert into tablesaleinfo (InvoiceNo,ItemID,ItemName,Cost,QtySold,ItemDiscount,GrossTotal)values (?,?,?,?,?,?,?,?)";
  
              pst=conn.prepareStatement(sql2);
  
              pst.setString(1, invoice);
              pst.setString(2, id);
              pst.setString(3, name);
              pst.setString(4, cost);
              pst.setString(5, qty);
              pst.setString(6, itemDiscount);
              pst.setString(7, grossTotal);
  
              pst.execute();
               JOptionPane.showMessageDialog(null, "New  Data Saved...");
  
  
          }catch(SQLException | HeadlessException e){
              JOptionPane.showMessageDialog(null, "Error "+e);
              e.printStackTrace();
          }
  </code></pre>
  
  <p>I keep getting the error <code>java.sql.SQLException: Parameter index out of range (8 &gt; number of parameters, which is 7)</code>.</p>
  
  <p>Stack Trace is below;</p>
  
  <pre><code>java.sql.SQLException: Parameter index out of range (8 &gt; number of parameters, which is 7).
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:937)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:872)
  at com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3399)
  at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3384)
  at com.mysql.jdbc.PreparedStatement.setString(PreparedStatement.java:4110)
  at com.bit.project.Newsale.add_btnActionPerformed(Newsale.java:670)
  at com.bit.project.Newsale.access$700(Newsale.java:38)
  at com.bit.project.Newsale$10.actionPerformed(Newsale.java:431)
  </code></pre>
  
  <p>What is the error here ?</p>