數據庫查詢時遇到的一些錯誤


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語句在換行時,少了一個空格。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM