import org.junit.Test;
|
|
import java.sql.Connection;
|
import java.sql.DriverManager;
|
import java.sql.PreparedStatement;
|
import java.sql.SQLException;
|
|
/**
|
* @Author cheng
|
* @Date 2022/2/12 23:03
|
* @Desc
|
*/
|
public class SyncDataTest {
|
|
@Test
|
public void addData() throws SQLException, ClassNotFoundException {
|
|
int addDataNumber = 4961345+78;
|
Connection connection = getConnection("jdbc:mysql://127.0.0.1:3306/test_sync?autoReconnect=true&useUnicode=true&characterEncoding=utf8&useNewIO=true&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true", "com.mysql.cj.jdbc.Driver", "root", "root123");
|
PreparedStatement pst = connection.prepareStatement(
|
" INSERT INTO `sync_data_test` " +
|
"(`source_name`, `desc`,`source_TIMESTAMP`,`update_time`) " +
|
"VALUES (concat('这是增加的数据--',?),concat('这是测试数据描述--',?),now(),null)");
|
connection.setAutoCommit(false);
|
for (int i = 4961345; i < addDataNumber; i++) {
|
pst.setObject(1, i);
|
pst.setObject(2, i);
|
pst.addBatch();
|
if (i != 0 && i % 5000 == 0) {
|
pst.executeBatch();
|
connection.commit();
|
pst.clearBatch();
|
}
|
}
|
pst.executeBatch();
|
connection.commit();
|
pst.close();
|
connection.close();
|
}
|
|
public static Connection getConnection(String url, String driver, String user, String pwd) throws ClassNotFoundException, SQLException {
|
Class.forName(driver);
|
return DriverManager.getConnection(url, user, pwd);
|
}
|
|
}
|