import com.mysql.cj.jdbc.util.BaseBugReport; import org.junit.jupiter.api.Assertions; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLSyntaxErrorException; import java.sql.Statement; import java.util.Properties; public class BatchedPreparedBugReport extends BaseBugReport { private final Properties props; public BatchedPreparedBugReport() { props = new Properties(); props.setProperty("rewriteBatchedStatements", "true"); } @Override public void setUp() throws Exception { try (Connection connection = getConnection(getUrl(),props)) { try(Statement statement = connection.createStatement()) { statement.execute("CREATE TABLE area (id int primary key, code CHAR(2) unique not null, name varchar(50))"); } } } @Override public void tearDown() throws Exception { try (Connection connection = getConnection(getUrl(),props)) { try(Statement statement = connection.createStatement()) { statement.execute("DROP TABLE area"); } catch (SQLSyntaxErrorException ex) { if (!ex.getMessage().equals("Unknown table test.area")) { throw ex; } } } } @Override public void runTest() throws Exception { try (Connection connection = getConnection(getUrl(), props)) { try (PreparedStatement statement = connection.prepareStatement("INSERT INTO area(code,name) VALUES(?,?) as new ON DUPLICATE KEY UPDATE name=new.name")) { statement.setString(1, "JO"); statement.setString(2, "Jor"); statement.addBatch(); statement.setString(1, "US"); statement.setString(2, "United States"); statement.addBatch(); statement.setString(1, "JO"); statement.setString(2, "Jordan"); statement.addBatch(); Assertions.assertDoesNotThrow(statement::executeBatch); } } } }