Play 2.0 找不到 MySQL 驱动程序

标签 mysql playframework-2.0 scalaquery

我正在尝试将 ScalaQuery 与 play 2 一起使用,但我一直收到“”没有适合...的驱动程序”错误。数据库连接与 Anorm/Nina 配合良好。 这是我的 ScalaQuery 代码:

object Client extends Table[(Int, String)]("Client") {
val database = Database.forURL("jdbc:mysql://localhost/play2test", driver = "com.mysql.jdbc.Driver" , user="root", password="root")

  def id = column[Int]("id", O NotNull, O AutoInc)

  def name = column[String]("name", O NotNull)

  def * = id ~ name
  def findAll = database.withSession {
    implicit db: Session =>
      (for (t <- this) yield t.id ~ t.name).list
  }
}

我添加了 sbt 依赖:

"mysql" % "mysql-connector-java" % "5.1.21"

我在 application.conf 上有这个

db.default.driver=com.mysql.jdbc.Driver
db.default.url="mysql://root:root@127.0.0.1/play2test"
db.default.user=root
db.default.password=root

(我尝试将 forDataSource 方法与 play 的 DB.getDataSource() 一起使用,但没有得到更好的结果)

一件尴尬的事情是我无法导入 com.mysql._,所以显然驱动程序甚至都没有下载(尽管 sbt 说它已经下载了)。我什至尝试下载 jar 并将其手动添加到我项目下的/lib 文件夹中,但导入仍然无法正常工作。

我被卡住了,我需要一点帮助。 :(

编辑: 我删除了“jdbc:mysql://localhost/play2test”并重写了它(在另一个线程上找到了那个提示),现在我遇到了一个新问题:

[MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '."id","t1"."name" FROM "Client" "t1"' at line 1]

为什么 ScalaQuery 对 MySQL 使用双引号以及如何更改它?

编辑2: 问题已解决,我错误地导入了 ScalaQuery 的 SQL 驱动程序。

最佳答案

我复制/粘贴了一个基于 O2 的代码,但忘记更改 SQLDriver 导入:

import org.scalaquery.ql.extended.MySQLDriver.Implicit._

关于Play 2.0 找不到 MySQL 驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11557611/

相关文章:

scala - 如何使用 Slick 使用过滤器计算结果?

scalaquery 问题没有隐式 session

scala - 如何从运行时参数指定 SLICK Query sortBy 列?

mysql - 查询mysql的帖子和评论系统

java - 在play框架中动态创建Date

scala - Play Framework, Specs2 - 直接从单元测试调用 Controller 方法

javascript - 单页 Play 应用

php - 在 PHP 中删除当前个人资料图像后的默认个人资料图像

php - 在 Yii2 的 SqlDataProvider 中使用 SQL_CALC_FOUND_ROWS

php - 在不转义的情况下将用户数据存储在数据库中