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

  • 相关阅读:
    Shell使用
    从一道面试题谈linux下fork的运行机制
    老了,问题定位难了,xml编码解析
    javacc
    C++概述
    Notepad++中设置Windows、Unix、Mac三种行尾换行符格式间的转换
    玩转html5(一)-----盘点html5新增的那些酷酷的input类型和属性
    Java Drp项目实战—— 环境搭建
    cocos2d-x游戏开发 跑酷(八) 对象管理 碰撞检測
    电话拨号盘(带触摸振动反馈)
  • 原文地址:https://www.cnblogs.com/zeroingToOne/p/8779428.html
Copyright © 2011-2022 走看看