Tag Archives: Column count doesn‘t match value count at row 1

[Solved] mybatis Bulk Insert Error: Column count doesn‘t match value count at row 1

Mybatis batch insert problem

Incorrect wording:

INSERT INTO t_csm_customer_product(id, customer_code, product_code) values
<foreach collection="lists" close=")" open="(" index="i" item="cstProduct" separator=",">
    #{cstProduct.id},
    #{cstProduct.customerCode},
    #{cstProduct.productCode}
</foreach>

Error Messages: Error updating database…Cause: java.sql.SQLException: Column count doesn’t match value count at row 1
Print sql:

INSERT INTO table(id, name, value) values ( ?,?,?,?,?,?) 

The whole bracket is enclosed

The SQL we want:

INSERT INTO table(id, name, value) values ( ?,?,?),(?,?,?)  

Adjust XML to:

INSERT INTO t_csm_customer_product(id, customer_code, product_code) values
<foreach collection="lists" index="i" item="cstProduct" separator=",">
    (#{cstProduct.id},
    #{cstProduct.customerCode},
    #{cstProduct.productCode})
</foreach>

Missing parameter () in key foreach

[Solved] Column count doesn‘t match value count at row 1

Preface

    If this error is reported, it must be that there is no error in the SQL, just a failure to interact with the database, so there is no need to change the code or
 to fix the logic.

Solutions

**The only thing to do is to check whether the mapping relationship between the properties of JavaBean entity fields and those in the library is OK**