I'm trying to use ScalaQuery with play 2 but I keep getting a ""no suitable driver for ...' error. The database connection works fine with Anorm/Nina. Here's my ScalaQuery code :
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
}
}
I added the sbt dependency:
"mysql" % "mysql-connector-java" % "5.1.21"
And I have this on 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
(I tried to use the forDataSource method along with play's DB.getDataSource() but I didn't get any better results)
One awkward thing is that I cannot import com.mysql._, so apparently the driver wasn't even downloaded (despite sbt saying that it did). I tried even to download the jar and add it manually to a /lib folder under my project but the import still not working.
I'm stuck and I need a little help please. :(
EDIT: I deleted the "jdbc:mysql://localhost/play2test" and rewrited it (found that tip on another thread) and now I'm having a new problem :
[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]
Why is ScalaQuery using double-quotes for MySQL and how to change that ?
Edit2 : Problem solved, I had the wrong import for ScalaQuery's SQL driver.
I copy/pasted an O2 based code and forgot to change the SQLDriver import:
import org.scalaquery.ql.extended.MySQLDriver.Implicit._