title: I am getting this error: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '1' for key 'employee.PRIMARY'
body: <p>I'm studying Java EE with JDBC. I created a simple employee registration form so, when I input the required data, it throws errors and I know it duplicates the primary key (id) in the database. Although, the id column of the database is set up as AUTO_INCREMENT but it still overwrites the same id after each registration. Anyone knows what's wrong with this? Any suggestion is appreciated!</p>
  <p>JavaBean:</p>
  <pre><code>public class Employee {
  
      private String firstName;
      private String lastName;
      private String username;
      private String password;
      private String address;
      private String contact;
  
      public String getFirstName() {
          return firstName;
      }
  
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
  
      public String getLastName() {
          return lastName;
      }
  
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
  
      public String getUsername() {
          return username;
      }
  
      public void setUsername(String username) {
          this.username = username;
      }
  
      public String getPassword() {
          return password;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  
      public String getAddress() {
          return address;
      }
  
      public void setAddress(String address) {
          this.address = address;
      }
  
      public String getContact() {
          return contact;
      }
  
      public void setContact(String contact) {
          this.contact = contact;
      }
  
  }
  </code></pre>
  <p>EmployeeDao:</p>
  <pre><code>public class EmployeeDao {
  
      private String db_url = &quot;jdbc:mysql://localhost:3306/test&quot;;
      private String db_user = &quot;root&quot;;
      private String db_password = &quot;root&quot;;
  
      public int registerEmployee(Employee employee) throws ClassNotFoundException {
  
          String sql_insert = &quot;INSERT INTO employee VALUES(?,?,?,?,?,?,?)&quot;;
          int result = 0;
          Class.forName(&quot;com.mysql.cj.jdbc.Driver&quot;);
          try {
              Connection conn = DriverManager.getConnection(db_url, db_user, db_password);
              PreparedStatement ps = conn.prepareStatement(sql_insert);
              ps.setInt(1, 1);
              ps.setString(2, employee.getFirstName());
              ps.setString(3, employee.getLastName());
              ps.setString(4, employee.getUsername());
              ps.setString(5, employee.getPassword());
              ps.setString(6, employee.getAddress());
              ps.setString(7, employee.getContact());
  
              System.out.println(ps);
  
              result = ps.executeUpdate();
  
              ps.close();
              conn.close();
          } catch (SQLException e) {
              e.printStackTrace();
          }
  
          return result;
      }
  }
  </code></pre>
  <p>The page that shows a successful message:</p>
  <pre><code>&lt;body&gt;
  &lt;jsp:useBean id=&quot;employee&quot; class=&quot;jsp.jdbc.javaBean.Employee&quot;&gt;&lt;/jsp:useBean&gt;
  &lt;jsp:setProperty property=&quot;*&quot; name=&quot;employee&quot; /&gt;
  
  &lt;%
      EmployeeDao employeeDao = new EmployeeDao();
      int status = employeeDao.registerEmployee(employee);
      if(status &gt; 0){
          out.println(&quot;You have successfully registered&quot;);
      }
  %&gt;
  &lt;br/&gt;&lt;br/&gt;
  &lt;a href=&quot;EmployeeRegistrationFrom.html&quot;&gt;Register&lt;/a&gt;
  </code></pre>