zoukankan      html  css  js  c++  java
  • 数据库查询时遇到的一些错误

    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语句在换行时,少了一个空格。

  • 相关阅读:
    Android Studio Tips -- 布局预览
    weibo sdk Multiple dex files define Lcom/sina/weibo/sdk/BuildConfig
    Android Studio下添加assets目录
    Android中bitmap图片透明度的处理(以撕美女衣服为例)
    Android中使用ViewPage进行广告轮播测试代码
    比赛现场打分管理平台概述
    排行榜每页默认为8行,如何把默认行数改成12行或其他行数?
    复习重点补充-
    字典读写训练
    Python爬网常见方法:find_all与re的结合使用
  • 原文地址:https://www.cnblogs.com/zeroingToOne/p/8779428.html
Copyright © 2011-2022 走看看