Search code examples
javamysqlplayframeworkplayframework-2.2

Adding MySql to playframework 2.2.1


I am trying to connect to a mysql database using the play framework. From my own searching, I know I need to add this line somewhere:

"mysql" % "mysql-connector-java" % "5.1.18"

However, in every documentation/similar question it says that this line either goes into the Build.scala file or the build.sbt file and I have neither of those files. When I created my application (as a java app) it only gave me a build.properties and plugins.sbt which are inside the project folder.

Does anyone know how where to add this line? Do I need to create one of those files?

My build.properties file:

 sbt.version=0.13.0

And

plugins.sbt

// Comment to get more information during initialization
logLevel := Level.Warn

// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1")

UPDATE: After adding

addSbtPlugin("mysql" % "mysql-connector-java" % "5.1.18") to my plugins file:

enter image description here


Solution

  • You are required to add lines in your sbt file.

    libraryDependencies ++= Seq(
     jdbc,
     anorm,
     cache,
     "mysql" % "mysql-connector-java" % "5.1.18"
    )
    

    And after that change into your application.config by uncommenting

    #
    db.default.driver=com.mysql.jdbc.Driver
    db.default.url="jdbc:mysql://127.0.0.1:3306/test"
    db.default.user="root"
    db.default.password=""