Having following code, how do I know if the execute() method resulted in insert or in update?:
Connection c = DriverManager.getConnection(connectionString);
Use executeUpdate instead as it returns an int
row count.
UPDATE 1: According to the MySQL INSERT ... ON DUPLICATE KEY UPDATE documentation:
With ON DUPLICATE KEY UPDATE, the affected-rows value per row is 1 if the row is inserted as a new row, and 2 if an existing row is updated.
UPDATE 2: INSERT IGNORE
may also be an option:
INSERT IGNORE INTO `table`(`field1`) VALUES (?)
executeUpdate
should return 1 when a new row is inserted and 0 when there is a duplicate.