简体   繁体   中英

I get “Cannot connect to database [default]” when I don't use dependency “mysql” % “mysql-connector-java” % “5.1.21”

I have created a project with Play and Scala and followed this tutorial https://www.playframework.com/documentation/2.2.x/ScalaDatabase .

In my application.conf I used

db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/library"
db.default.user=root
db.default.pass=""

I also created the library DB with Apache & MySQL using wamp.

So when I run activator run I get " Cannot connect to database [default] " error

If I add this dependency in build.sbt "mysql" % "mysql-connector-java" % "5.1.21" and run again activator run I get the defaul page "Welcome to Play"

Do you have any idea why is this happening?

Thank you very much!

As this section says, only the H2 driver was bundled with 2.2 and therefore you would need to add a dependency for the MySQL connector.

Without the connector, you got the error there. The error you pasted there would be the top-level exception and if you looked further down the stacktrace, you'd see something like Caused by: slick.SlickException: Error getting instance of Slick driver "com.mysql.jdbc.Driver" (2.4 error but 2.2 error would look similar.)

With the connector, you got saw the Play default page, which is what you would see if your app that you had created from the template was successfully started. This meant that all were good and you were all set. :)

(PS welcome to Stack Overflow :))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM