title: java.sql.SQLException: Duplicate entry for key when trying to insert in database from java
body: <p>this is my table in mysql</p>
  
  <pre><code>CREATE TABLE `mydb`.`mytab` (
  
      `email` VARCHAR(45) NOT NULL,
      `name` VARCHAR(45) NULL,
  
      PRIMARY KEY (`email`));
  </code></pre>
  
  <p>and my code in java is</p>
  
  <pre><code>Class.forName("com.mysql.jdbc.Driver");
  Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/spacespacer", "root", "");
  PreparedStatement state=con.prepareStatement("INSERT INTO `spacespacer`.`mytab` VALUES (?, ?);");
  state.setString(1, "email");
  state.setString(2, "name");
  state.executeUpdate();
  </code></pre>
  
  <p>and this is what i get when i run the file in netbeans</p>
  
  <pre><code>run:
  Exception in thread "main" java.sql.SQLException: Duplicate entry 'email' for key 'PRIMARY'
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2847)
  at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
  at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1347)
  at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:958)
  at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1957)
  at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1880)
  at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1741)
  at spacespacer.SpaceSpacer.main(SpaceSpacer.java:30)
  Java Result: 1
  BUILD SUCCESSFUL (total time: 0 seconds)
  </code></pre>
  
  <p>so how do i get it to work?</p>
  
  <p>thanks for replying</p>