Cause: java.sql.SQLIntegrityConstraintViolationException: Column ‘xxx‘ cannot be null

1、报错信息

2、定位错误的范围

### SQL: insert into business             (businessId,password,salt,businessName,businessAddress,businessExplain,starPrice,deliveryPrice)             values (?,?,?,?,?,?,?,?)

3、从上述报错内容已知错误存在于SQL的insert into操作里,然后跳转到BuseineeMapper.xml里

4、定位到BusinessMapper.xml里的id为add的部分

    
        
        
            select last_insert_id() as businessId
        
        insert into business
            (businessId,password,salt,businessName,businessAddress,businessExplain,starPrice,deliveryPrice)
            values (#{businessId},#{password},#{salt},#{businessName},#{businessAddress},#{businessExplain},#{starPrice},#{deliveryPrice})
    

5、发现sql语句和xml标签没写错,排除问题存在于BusinessMapper.xml

6、最后发现没有给businessId勾选自动递增,selectKey查询不了最后一个id

Cause: java.sql.SQLIntegrityConstraintViolationException: Column ‘xxx‘ cannot be null_第1张图片

7、勾选上自动递增并保存,运行成功

你可能感兴趣的:(java,mysql,java,sql,数据库)