this is my table in mysql
CREATE TABLE `mydb`.`mytab` (
`email` VARCHAR(45) NOT NULL,
`name` VARCHAR(45) NULL,
PRIMARY KEY (`email`));
and my code in java is
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();
and this is what i get when i run the file in netbeans
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)
so how do i get it to work?
thanks for replying