数据库插入操作怎么出错了

这是什么原因导致的呢?
sql语句代码


<insert id="insertUser">
        INSERT  INTO sys_user
        (
        id,
        name ,
        password ,
        sex ,
        address ,
        point ,
        creat_time,
        power ,
        account ,
        professional
        )
        values (
        null,
        #{name},
        #{password},
        #{sex},
        #{address}
        #{point},
        0,
        #{power},
        #{account},
        #{professional}
        )
    insert>

错误提示:

Error updating database. Cause: java.sql.SQLException: Column count doesn't match value count at row 1

The error may exist in file [D:\vuedemo\salaryManage\target\classes\mapper\UserMapper.xml]

The error may involve defaultParameterMap

The error occurred while setting parameters

SQL: INSERT INTO sys_user ( id, name , password , sex , address , point , creat_time, power , account , professional ) values ( null, ?, ?, ?, ? ?, 0, ?, ?, ? )

Cause: java.sql.SQLException: Column count doesn't match value count at row 1

; bad SQL grammar []; nested exception is java.sql.SQLException: Column count doesn't match value count at row 1] with root cause
数据库结构:

img

根据错误提示,问题出现在"Column count doesn't match value count at row 1",意思是列数和值的数量不匹配。在你的SQL语句中,有10个列和9个占位符(#{...}),这意味着你缺少一个值。

根据你的代码,似乎是在address和point之间缺少了一个逗号。你的SQL语句应该是这样的:

INSERT INTO sys_user (
    id,
    name,
    password,
    sex,
    address,
    point,
    creat_time,
    power,
    account,
    professional
) VALUES (
    null,
    #{name},
    #{password},
    #{sex},
    #{address},
    #{point},
    0,
    #{power},
    #{account},
    #{professional}
)


请注意,在address和point之间添加了一个逗号。

希望这可以解决你的问题。

插入语句和你的表定义不匹配造成的。

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^