【问题标题】:Bad SQL grammar exception after deploying in server在服务器中部署后出现错误的 SQL 语法异常
【发布时间】:2017-10-14 09:56:09
【问题描述】:

我正在使用 MySql,Spring MVC。

当我在我的计算机 (localhost) 上运行我的代码时,它运行良好。但是在远程服务器上部署它后,它显示 Bad SQL 语法异常

这是我的远程服务器数据库自定义错误的屏幕截图。 (来自 phpMyAdmin 的屏幕截图)

这是文本格式的错误:

PreparedStatementCallback;错误的 SQL 语法 [插入匹配项 (id, 标题,位置,number_of_players,结束,team1,team2,折腾,状态, 结果,team_init,match_end,match_started,match_views,加书签, 公告、锦标赛、创建日期、开始日期、活动日期、 asst_scorer, start_date_string) 值 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)];嵌套异常是 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 你有一个 SQL 语法错误;检查与您对应的手册 MariaDB 服务器版本,用于在 'over, team1, 附近使用正确的语法, team2,折腾,状态,结果,team_init,match_end,match_started,m' 在第 1 行

这是我在 MySql 表中插入数据的 Java 代码

public boolean createMatch(Match match) {

    BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(match);

    return jdbc.update(
        "insert into matchs (id, title, location, number_of_players, over, team1, team2, toss, status, result, team_init, match_end, match_started, match_views, bookmarked, announcement, tournament, create_date, start_date, active_date, asst_scorer, start_date_string) values (:id, :title, :location, :number_of_players, :over, :team1, :team2, :toss, :status, :result, :team_init, :match_end, :match_started, :match_views, :bookmarked, :announcement, :tournament, :create_date, :start_date, :active_date, :asst_scorer, :start_date_string)",
        params) == 1;
}

【问题讨论】:

  • 问题是用Mysql标记的,但是stacktrace属于MariaDb,你是在本地和远程运行不同的数据库服务器吗?
  • 是不同的mysql服务器
  • 您应该在本地和生产环境中运行相同的环境。这样您就可以避免此类问题。

标签: java mysql spring-mvc badsqlgrammarexception


【解决方案1】:

OVER 是 MariaDB 关键字: https://mariadb.com/kb/en/library/window-functions-overview/

将该列重命名为其他名称。我还强烈建议在您的所有环境中使用相同的数据库,否则您的测试将检测到生产中不会发生的错误,或者不会检测到生产中发生的错误。

【讨论】:

  • 在 MySQL 8 中也是如此。如果无法重命名,该字段上的反引号将避免该问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-12-02
  • 1970-01-01
  • 2014-05-28
  • 2017-08-05
  • 2021-10-23
  • 1970-01-01
  • 2017-07-03
相关资源
最近更新 更多