简体   繁体   English

JdbcTemplate.update从一个表到另一个表的输入

[英]JdbcTemplate.update input from one table to other

I have a table "temp" and "data". 我有一个表“temp”和“data”。 I want to copy some specific data from "temp" table to "data" table along with some of my user data in batches. 我想将一些特定的数据与我的一些用户数据一起从“临时”表复制到“数据”表中。 Currently I have a code something like 目前我有一个类似的代码

JdbcTemplate.update("insert into Data(a, b, c, d, e) "
                + "select a, b, c, ?, e"
                + "from Temp where d= ?", id, Date);

But i want this to be done in batches as the data >10,00,000 rows and this fills us my transactional log with this single transaction, so need to break this single transaction into multiple. 但我希望这可以分批完成,因为数据> 10,00,000行,这使我们的事务日志充满了这个单一事务,所以需要将这个单个事务分成多个。

Try creating a List of all the parameters you want to insert and use a batch update using the following method. 尝试创建要插入的所有参数的List ,并使用以下方法使用批量更新。

public void insertBatch(final List<TempObj> TempList) {

   String str = "Your query here.";

   getJdbcTemplate().batchUpdate(str, new BatchPreparedStatementSetter() {

        @Override
        public void setValues(PreparedStatement ps, int i)
            throws SQLException {

            TempObj obj = TempList.get(i);
            ps.setString(1, obj.getId());
            ps.setDate(2, obj.getDate());

        }

        @Override
        public int getBatchSize() {
           return TempList.size();
        }

    });

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM