实体类与数据库字段不匹配问题,java.sql.SQLSyntaxErrorException: Unknown column 'xxx' in 'field list'

Posted taopanfeng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实体类与数据库字段不匹配问题,java.sql.SQLSyntaxErrorException: Unknown column 'xxx' in 'field list'相关的知识,希望对你有一定的参考价值。

控制台报错

### Error querying database.  Cause: java.sql.SQLSyntaxErrorException: Unknown column ‘user_name‘ in ‘field list‘
### The error may exist in panfeng/mapper/StudentMapper.java (best guess)
### The error may involve panfeng.mapper.StudentMapper.selectByPrimaryKey-Inline
### The error occurred while setting parameters
### SQL: SELECT id,user_name,password,email  FROM student  WHERE  id = ?
### Cause: java.sql.SQLSyntaxErrorException: Unknown column ‘user_name‘ in ‘field list‘
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: Unknown column ‘user_name‘ in ‘field list‘] with root cause

java.sql.SQLSyntaxErrorException: Unknown column ‘user_name‘ in ‘field list‘
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.16.jar:8.0.16]
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.16.jar:8.0.16]

 

浏览器报错

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue Aug 06 13:10:39 CST 2019
There was an unexpected error (type=Internal Server Error, status=500).
### Error querying database. Cause: java.sql.SQLSyntaxErrorException: Unknown column ‘user_name‘ in ‘field list‘ ### The error may exist in panfeng/mapper/StudentMapper.java (best guess) ### The error may involve panfeng.mapper.StudentMapper.selectByPrimaryKey-Inline ### The error occurred while setting parameters ### SQL: SELECT id,user_name,password,email FROM student WHERE id = ? ### Cause: java.sql.SQLSyntaxErrorException: Unknown column ‘user_name‘ in ‘field list‘ ; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: Unknown column ‘user_name‘ in ‘field list‘

 

出错的时候

 技术图片

 

修改之后,修改之后重启,就可以正常访问了!!!

 技术图片

 

以上是关于实体类与数据库字段不匹配问题,java.sql.SQLSyntaxErrorException: Unknown column 'xxx' in 'field list'的主要内容,如果未能解决你的问题,请参考以下文章

类型不匹配的值类与值字段和导入的猫任一语法

Java自定义注解注解实现实体类与数据库表字段的映射

Java自定义注解注解实现实体类与数据库表字段的映射

hibernate进行多表查询每个表中各取几个字段,也就是说查询出来的结果集没有一个实体类与之对应如何解决?

php 实体和/或字段定义不匹配

双数据源实体类映射oracle字段有的字段无法映射