我正在使用Play Framework(2.3.1)和Slick(播放版本0.8.0-M1)和MySQL数据库(5.5.28)。
我的一个查询导致MySQLSyntaxErrorException:
Preparing statement: select x2."id", x2."course_id", x2."trainee_id", x2."transaction_id" from "trainee_grouptraining_GroupBooking" x2 where x2."course_id" = 1
问题似乎是双引号,因为其他查询工作得很好,他们使用单引号,如下所示:
Preparing statement: select x2.`id`, x2.`courseLanguage`, x2.`date`, x2.`description`, x2.`duration`, x2.`kind`, x2.`maxParticipants`, x2.`name`, x2.`courseType_id`, x2.`trainer_id` from `Course` x2 where x2.`id` = 1
我该怎么办?
答案 0 :(得分:8)
我猜您正在导入
scala.slick.driver.JdbcDriver.simple._
您应该导入
scala.slick.driver.MySQLDriver.simple._
代替。
答案 1 :(得分:0)
MySQL使用每个默认反引号来引用标识符。您可以使用SQL Mode ANSI_QUOTES启用双引号
<强> ANSI_QUOTES 强>
将“视为标识符引用字符(就像`引用 字符)而不是字符串引号字符。你仍然可以使用“`” 在启用此模式时引用标识符。启用ANSI_QUOTES后, 你不能使用双引号来引用文字字符串, 因为它被解释为标识符。
或只是使用反引号。