【解决方案】Mysql 数据库千万数据插入脚本

一.背景

      要做数据模拟,需要在测试环境创建7千万的流水数据,进行迁移的模拟动作。

二.具体代码

 private static final String DB_URL = "jdbc:mysql://IP:3306/twallet_dev?zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useAffectedRows=true&rewriteBatchedStatements=true";
    private static final String USER = "root";
    private static final String PASS = "123456";
    private static final String TABLE_NAME = "tstd_jour_copy1";
    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    private static final DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyyMMdd");
    private SnowflakeIdWorker snowflakeIdWorker = new SnowflakeIdWorker(0,0);



  public void testinsert() {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");

            Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);

            String sql = "INSERT INTO " + TABLE_NAME + " (`code`, `type`, `user_id`, `account_number`, `account_type`, `currency`, `biz_type`, `biz_note`, `en_biz_note`, `trans_object`, `trans_object_user_id`, `trans_amount`, `pre_amount`, `post_amount`, `status`, `push_status`, `channel_type`, `channel_order`, `prev_jour_code`, `ref_no`, `remark`, `create_datetime`, `work_date`, `check_user`, `check_note`, `check_datetime`, `adjust_user`, `adjust_note`, `adjust_datetime`, `trans_order_no`, `subsidiary_code`)" +
                    " VALUES (?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
     
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

上善若水-学者至上

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值