JDBC PreparedStatement Batch continue insert on error

前端 未结 1 1351
我在风中等你
我在风中等你 2021-02-15 10:16

Hello guy I create a Batch with a PreparedStatement in java like this

for(Item  item: list){
    ps.setString(1, item.getSome());
    ps.setString(2         


        
1条回答
  •  北荒
    北荒 (楼主)
    2021-02-15 10:27

    I think it can be summed up in one word IGNORE

    When you run the batch with this

    sb.append("INSERT IGNORE INTO `FRT_DB`.`ITEM` ");
    

    This NOT throw a Exception realted with constrains, this pass over, and still old data in your rows

    If you need save the 'new data' you change for INSERT ... ON DUPLICATE KEY Statement, but , right now think dont need it.

    Commit or rollback is not necesary in your code @Transactional work for you.

    Your big try { only crash in SqlException not in BatchUpdateException

    You only need add allowMultiQueries beacuse other and default true

    http://dev.mysql.com/doc/connector-j/en/connector-j-reference-configuration-properties.html

    0 讨论(0)
提交回复
热议问题