2012-07-19 51 views
2

我正在嘗試使用ScalaQuery和Play 2,但我總是收到一個「」沒有合適的驅動程序......「錯誤。數據庫連接與Anorm/Nina很好地結合。 這裏是我的ScalaQuery代碼:未找到Play 2.0的MySQL驅動程序

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:[email protected]/play2test" 
db.default.user=root 
db.default.password=root 

(我試圖沿着使用forDataSource方法與玩的DB.getDataSource()但我沒有得到任何更好的結果)

一個尷尬的問題是我無法導入com.mysql._,所以顯然驅動程序甚至沒有下載(儘管它說它做到了)。我甚至嘗試下載jar並手動添加到我的項目下的一個/ lib文件夾,但導入仍然不起作用。

我被卡住了,我需要一點幫助。 :(

編輯: 我刪除了 「的jdbc:mysql的://本地主機/ play2test」 和rewrited它(發現另一個線程尖),現在我有一個新的問題:

[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和如何更改

EDIT2: 問題解決了,我有ScalaQuery的SQL驅動程序錯誤的進口

+0

很高興你解決了這個問題,但是請添加一個答案並將其標記爲正確的答案(在接下來的兩天內) – biesior 2012-07-19 10:01:10

回答

0

我複製/粘貼一個基於O2代碼,忘了。更改SQLDriver我mport:

import org.scalaquery.ql.extended.MySQLDriver.Implicit._ 
相關問題