PCP PCP - 4 months ago 82
SQL Question

connect MySQL database with play-framework 2.5

I am trying to connect MySQL database with Play-framework- Java 2.5.4.

I am getting this error,

either dataSource or dataSourceClassName is required


These are the connection codes that I am using inside App.conf file,

db {
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost:3306/playdb"
db.default.user="root"
db.default.password="9413678957"
}


But its giving me following errors while connecting :

caused by: java.lang.IllegalArgumentException: either dataSource or dataSourceClassName is required
at com.zaxxer.hikari.HikariConfig.validate(HikariConfig.java:785)
at play.api.db.HikariCPConfig.toHikariConfig(HikariCPModule.scala:141)
at play.api.db.HikariCPConnectionPool$$anonfun$1.apply(HikariCPModule.scala:57)
at play.api.db.HikariCPConnectionPool$$anonfun$1.apply(HikariCPModule.scala:54)
at scala.util.Try$.apply(Try.scala:192)
at play.api.db.HikariCPConnectionPool.create(HikariCPModule.scala:54)
at play.api.db.PooledDatabase.createDataSource(Databases.scala:199)
at play.api.db.DefaultDatabase.dataSource$lzycompute(Databases.scala:123)
at play.api.db.DefaultDatabase.dataSource(Databases.scala:121)
at play.api.db.DefaultDatabase.getConnection(Databases.scala:142)


When I am connecting to mysql database with same(same as in App.conf)


  • url (jdbc:mysql://localhost:3306/playdb)

  • username

  • password



Using Intellij, its working fine.

Please help me by telling me what I am doing wrong.

PCP PCP
Answer

this error killed my lot of time.

Here is what worked for me,

uncomment these line.

    play.db {
             config = "db"
             default = "default" 
    } 

then

    db {

  default.driver=com.mysql.jdbc.Driver
  default.url="jdbc:mysql://localhost:3306/playdb"
  default.username=root
  default.password="9403678957"
}

don't need db.*, as you already in the db set range.

Lots of thanks to this answer.

Comments