package test;

import static org.junit.Assert.assertEquals;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import mockit.Expectations;
import mockit.integration.junit4.JMockit;

import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(JMockit.class)
public class PreparedStatementTest {

    private int executeUpdate(String sql) throws SQLException {
        try (Connection conn =
                DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test?user=root&password=password");
                PreparedStatement stmt = conn.prepareStatement(sql);) {
            return stmt.executeUpdate();
        } catch (SQLException e) {
            throw e;
        }
    }

    @Test
    public void test() throws SQLException {
        new Expectations() {
            {
            }
        };
        String sql =
                "insert into employees (id,job_code, store_id) values (7, 4, 19) on duplicate key update id = 7, job_code = 4, separated = now();";
        int executeUpdate1 = executeUpdate(sql);
        int executeUpdate2 = executeUpdate(sql);
        int executeUpdate3 = executeUpdate(sql);

        System.out.println("1回目 : " + executeUpdate1);
        System.out.println("2回目 : " + executeUpdate2);
        System.out.println("3回目 : " + executeUpdate3);

        assertEquals(executeUpdate1, 1);
        assertEquals(executeUpdate2, 2);
        assertEquals(executeUpdate3, 0);
    }
}

@@ -1496,8 +1496,708 @@
     %7D%0A%7D%0A
+%0A%0A/*%0A%E3%83%A1%E3%83%A2%0A%0ADDL%0A%0ACREATE SCHEMA %60new_schema%60 DEFAULT CHARACTER SET utf8 ;%0A%0ACREATE TABLE %60employees%60 (%0A   %60id%60 int(11) NOT NULL,%0A   %60fname%60 varchar(30) DEFAULT NULL,%0A   %60lname%60 varchar(30) DEFAULT NULL,%0A   %60hired%60 date NOT NULL DEFAULT '1970-01-01',%0A   %60separated%60 date NOT NULL DEFAULT '9999-12-31',%0A   %60job_code%60 int(11) NOT NULL,%0A   %60store_id%60 int(11) NOT NULL,%0A   PRIMARY KEY (%60id%60,%60job_code%60,%60store_id%60)%0A ) ENGINE=InnoDB DEFAULT CHARSET=utf8%0A /*!50100 PARTITION BY RANGE (store_id)%0A (PARTITION p0 VALUES LESS THAN (6) ENGINE = InnoDB,%0A  PARTITION p1 VALUES LESS THAN (11) ENGINE = InnoDB,%0A  PARTITION p2 VALUES LESS THAN (16) ENGINE = InnoDB,%0A  PARTITION p3 VALUES LESS THAN (21) ENGINE = InnoDB) */%0A

Update PreparedStatementTest.java