数据库查询时遇到的一些错误

1. 在页面输入内容进行搜索时,报错FUNCTION login.CONCAT does not exist

四月 10, 2018 2:39:49 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [springmvc] in context with path [/SpringDemo] threw exception [Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: 
### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: FUNCTION login.CONCAT does not exist
### The error may exist in com/game/mapper/NoticesMapper.java (best guess)
### The error may involve com.game.mapper.NoticesMapper.count-Inline
### The error occurred while setting parameters
### SQL: SELECT count(*) FROM notices WHERE (  noticeName LIKE CONCAT ('%',?,'%') )
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: FUNCTION login.CONCAT does not exist
; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: FUNCTION login.CONCAT does not exist] with root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: FUNCTION login.CONCAT does not exist

原因:函数和括号之间不能有空格

SELECT * FROM Notices WHERE noticeContent LIKE CONCAT('%',#{notice.noticeContent},'%')

2.根据id删除数据时,报错:Unknown column 'id' in 'where clause'

四月 10, 2018 3:59:22 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [springmvc] in context with path [/SpringDemo] threw exception [Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: 
### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'id' in 'where clause'
### The error may involve com.game.mapper.NoticesMapper.deleteById-Inline
### The error occurred while setting parameters
### SQL: delete from notices where id = ?
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'id' in 'where clause'
; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'id' in 'where clause'] with root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'id' in 'where clause'

原因:SQL语句中的字段与数据库中的字段不对应

//根据id删除公告
@Delete(" delete from notices where id = #{id} ")//数据库中的字段是noticeID,而这里写成了id
void deleteById(@Param("id") Integer id);

3. 想起来一个之前没用框架时因为SQL语句空格问题导致的错误,写一块吧

报错:mysql:Not unique table/alias: 'student'
原因:eclipse中的SQL语句在换行时,少了一个空格。

原文地址:https://www.cnblogs.com/zeroingToOne/p/8779428.html