title: Insert values to mysql Java
body: <p>It gives this error:</p>
  
  <blockquote>
    <p>"<em>java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).</em> "  </p>
  </blockquote>
  
  <p>This is the code:</p>
  
  <pre><code>public void insertData(int id,String name, String status, String age){
  
  
  
       String sql = "INSERT INTO student_table (id,name,satus,age) VALUES  (id,name,status,age)";
  
       try (Connection conn1 = this.connects();PreparedStatement Prepst= conn1.prepareStatement(sql)){
  
       Prepst.setInt(1, id);
       Prepst.setString(2, name);
       Prepst.setString(3, status);
       Prepst.setString(4, age);
       Prepst.executeUpdate();
  
       }catch(Exception e){
              System.err.println(e);
  
        }
  </code></pre>
  
  <p>If I   change  the parameter index to another value i.e.:</p>
  
  <pre><code>Prepst.setInt(0, id);
  </code></pre>
  
  <p>then it gives this error:</p>
  
  <blockquote>
    <p><em>" java.sql.SQLException: Parameter index out of range (0 &lt; 1 ). "</em></p>
  </blockquote>
  
  <p>----UPDATE -----</p>
  
  <p>I inserted this code: </p>
  
  <pre><code>String sql = "INSERT INTO student_table (id,name,satus,age) VALUES  (?,?,?,?)";
  </code></pre>
  
  <p>It produces the same:</p>
  
  <p><a href="https://i.stack.imgur.com/BQIvS.png" rel="nofollow noreferrer">RESULT</a></p>
  
  <p>Table Structure:</p>
  
  <p><img src="https://i.stack.imgur.com/W8hiP.png" alt="HERE"></p>