1

I'm trying to build an application using Play Framework 2.2 and Scala.

I'm not very acquainted to Java environments, so I don't know exactly what's going on.

To make it work with MySql, I should configure my conf/application.conf like this:

db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost:3306/sakila"
db.default.user=root
db.default.password="mypass"

Everything seems right to me, but when I try to access it, I get this:

 Cannot connect to database [default]

Why? These information are right! The database can be found at localhost:3306/sakila.

What am I doing wrong?

EDIT: Here is my stacktrace. It seems to be missing the mysql connector .jar file, or something like that. What should I do?

[success] Compiled in 734ms [error] c.j.b.h.AbstractConnectionHook - Failed to obtain initial connection Sle eping for 0ms and trying again. Attempts left: 0. Exception: null.Message:No sui table driver found for mysql://localhost:3306/world [error] application -

! @6gjp5p29b - Internal server error, for (GET) [/] ->

play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [
default]]
        at play.api.Configuration$.play$api$Configuration$$configError(Configura
tion.scala:92) ~[play_2.10.jar:2.2.1]
        at play.api.Configuration.reportError(Configuration.scala:570) ~[play_2.
10.jar:2.2.1]
        at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:252) ~[pla
y-jdbc_2.10.jar:2.2.1]
        at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:243) ~[pla
y-jdbc_2.10.jar:2.2.1]
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike
.scala:244) ~[scala-library.jar:na]
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike
.scala:244) ~[scala-library.jar:na]
Caused by: java.sql.SQLException: No suitable driver found for mysql://localhost
:3306/world
        at java.sql.DriverManager.getConnection(Unknown Source) ~[na:1.7.0_07]
        at java.sql.DriverManager.getConnection(Unknown Source) ~[na:1.7.0_07]
        at com.jolbox.bonecp.BoneCP.obtainRawInternalConnection(BoneCP.java:363)
 ~[bonecp.jar:na]
        at com.jolbox.bonecp.BoneCP.<init>(BoneCP.java:416) ~[bonecp.jar:na]
        at com.jolbox.bonecp.BoneCPDataSource.getConnection(BoneCPDataSource.jav
a:120) ~[bonecp.jar:na]
        at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:245) ~[pla
y-jdbc_2.10.jar:2.2.1]
[error] application -

! @6gjp5p29b - Internal server error, for (GET) [/] ->

play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [
default]]
        at play.api.Configuration$.play$api$Configuration$$configError(Configura
tion.scala:92) ~[play_2.10.jar:2.2.1]
        at play.api.Configuration.reportError(Configuration.scala:570) ~[play_2.
10.jar:2.2.1]
        at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:252) ~[pla
y-jdbc_2.10.jar:2.2.1]
        at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:243) ~[pla
y-jdbc_2.10.jar:2.2.1]
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike
.scala:244) ~[scala-library.jar:na]
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike
.scala:244) ~[scala-library.jar:na]
Caused by: java.sql.SQLException: No suitable driver found for mysql://localhost
:3306/world
        at java.sql.DriverManager.getConnection(Unknown Source) ~[na:1.7.0_07]
        at java.sql.DriverManager.getConnection(Unknown Source) ~[na:1.7.0_07]
        at com.jolbox.bonecp.BoneCP.obtainRawInternalConnection(BoneCP.java:363)
 ~[bonecp.jar:na]
        at com.jolbox.bonecp.BoneCP.<init>(BoneCP.java:416) ~[bonecp.jar:na]
        at com.jolbox.bonecp.BoneCPDataSource.getConnection(BoneCPDataSource.jav
a:120) ~[bonecp.jar:na]
        at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:245) ~[pla
y-jdbc_2.10.jar:2.2.1]
4
  • 1
    Did you include the jdbc dependency? Commented Dec 20, 2013 at 2:47
  • Did you add the dependency for the MySQL driver? Commented Dec 20, 2013 at 19:29
  • Yep. If I didn't, shouldn't it throw me an error based on the lack of a "com.mysql.jdbc.Driver" object? I'll try to check these dependencies, maybe the problem is something like a missing/incorrect .jar or something like that. I'm at work so I cant do it right now. Commented Dec 20, 2013 at 19:34
  • I updated the question. Take a look! Commented Dec 21, 2013 at 15:57

2 Answers 2

1

OK, I don't know what's going on.

I put this, and it started to work:

db.default.url="jdbc:mysql://localhost:3306/world"
db.default.driver="com.mysql.jdbc.Driver"
db.default.user="root"
db.default.pass="mypasswrd"
db.default.host="localhost"

Perhaps it needed a more detailed configuration, i just added the db.default.hostconfiguration, stringified everything with "" (I think this is not necessary, but whatever) and checked if mysql was listed in play dependencies listing. Since it was listed there (in fact it was the first entry), and the error didn't say it was a missing library, I just headed to Error when i try connect play with mysql 5.5 and fixed my configurations.

Thanks to everyone!

Sign up to request clarification or add additional context in comments.

Comments

0

You need to have the MySQL JDBC driver jar in your dependencies. This page in the documentation shows how to add the derby driver to the dependencies. Substitute the derby coordinates with the MySQL ones.

1 Comment

Well, I already had it... libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.27" I even tried to create a lib folder and put the mysql jar into it, but no success...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.