public class BatchInsert {
|
|
static final String ADDRESS = "127.0.0.1";
|
static final String PORT = "4006";
|
static final String USER = "maxuser";
|
static final String PASSWORD = "maxpwd";
|
static final String DB = "test";
|
|
public static void main(String[] args) {
|
try (Connection connection = DriverManager.getConnection("jdbc:mariadb://"
|
+ ADDRESS + ":" + PORT + "/" + DB + "?user=" + USER + "&password="
|
+ PASSWORD + "&useBatchMultiSendNumber=500")) {
|
Statement stmt = connection.createStatement();
|
stmt.execute("DROP TABLE IF EXISTS tt");
|
stmt.execute("CREATE TABLE tt (d int)ENGINE=BLACKHOLE");
|
for (int i = 0; i < 300; i++) {
|
stmt.addBatch("INSERT INTO tt(d) VALUES (1)");
|
if (i % 3 == 0) {
|
stmt.addBatch("SET @test2='aaa'");
|
}
|
}
|
stmt.executeBatch();
|
System.out.println("finished");
|
} catch (Exception e) {
|
System.out.println("Error: " + e.getMessage());
|
}
|
}
|
}
|