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


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

  • 相关阅读:
    TP3.2框架,实现空模块、空控制器、空操作的页面404替换||同步实现apache报错404页面替换
    调用支付宝PHP接口API实现在线即时支付功能(UTF-8编码)
    JQuery实现的 checkbox 全选;<select>下拉框功能
    使用PHP做移动端 api接口开发方法(适用于TP框架)
    Eclipse jvm启动参数在哪设置
    对 META标签 的一点点了解
    Java反射在整个程序运行中的位置
    Java 为什么要使用反射(通俗易懂的举例)
    粗略介绍Java AQS的实现原理
    Java并发包中线程池的种类和特点介绍
  • 原文地址:https://www.cnblogs.com/zeroingToOne/p/8779428.html
Copyright © 2020-2023  润新知