2017-10-14 77 views
0

我正在使用Spring MVC的MySql。在服務器中部署後出現錯誤的SQL語法異常

當我在我的電腦(localhost)上運行我的代碼時,它工作正常。但是,在遠程服務器上部署它之後,它會顯示錯誤的SQL語法異常

這是從我的遠程服務器數據庫自定義錯誤的屏幕截圖。 (截圖從phpMyAdmin的)

enter image description here

以下是在文本甲酸錯誤:

PreparedStatementCallback;錯誤的SQL語法[插入到匹配中( 公告,比賽,create_date,start_date,active_date) ,?,?,?,?,?,?,?,?,?,?,? asst_scorer,start_date_string) ,?)];嵌套的異常是 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL語法中有一個 錯誤;檢查位於第1行

對應於你的 MariaDB的服務器版本正確的語法使用近 '了,TEAM1, TEAM2,折騰,狀態,結果,team_init,match_end,match_started,M' 手冊這是我的Java代碼中插入數據在MySQL表

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; 
} 
+0

這個問題被標記爲Mysql,但堆棧跟蹤屬於MariaDb,你是否在本地主機和遠程運行不同的數據庫服務器? –

+0

是的不同的mysql服務器 –

+2

你應該在本地和生產環境中運行相同的環境。這樣你就可以避免這種問題。 –

回答

3

OVER是MariaDB的關鍵字: https://mariadb.com/kb/en/library/window-functions-overview/

該列重命名爲別的東西。我還強烈建議在所有環境中使用相同的數據庫,否則您的測試將檢測不會在生產中發生的錯誤,或者不會檢測生產中發生的錯誤。

+1

它也在MySQL 8中。如果無法重命名,則在該字段上的反引號將避免該問題 – Cez