DB Plugin is not registered in Play 2.0

2019-02-21 13:43发布

I just started working with play, and I modified the way I'm doing a SQL read and I'm now getting the following error:

[Exception: DB plugin is not registered.]

The code I have for this class is:

package models

import play.api.db._
import play.api.Play.current

import anorm._

case class Housing(id: Long, rent: String, address: String, street0: String, street1: String, neighbourhood: String)

object Housing {

  def all(): List[Housing] = DB.withConnection { implicit c =>
    SQL("select * from housing")().map { row =>
      Housing(row[Long]("id"), row[String]("rent"), row[String]("address"), row[String]("street0"),
        row[String]("street1"), row[String]("neighbourhood"))
    }.toList
  }

  def create(rent: String, address: String, street0: String, street1: String, neighbourhood: String) {}

  def delete(id: Long) {}

}

I'm not sure this is even the best way to do this, but using the ~ chain seemed like I'd just end up duplicating a bunch of stuff.

2条回答
beautiful°
2楼-- · 2019-02-21 14:14

Just make sure you provide the database configuration. For example, if you are using Play Framework's tutorial, uncomment this section.

# Database configuration
# ~~~~~ 
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
#
# db.default.driver=org.h2.Driver
# db.default.url="jdbc:h2:mem:play"
# db.default.user=sa
# db.default.password=""**

For more information, see Play Framework Database Configuration

查看更多
孤傲高冷的网名
3楼-- · 2019-02-21 14:34

Turns out that somehow in the application.conf the line:

dbplugin=disabled

had arisen. Not sure, I know I didn't put it in there, but commenting it out and fixing the remaining config errors in the JDBC Url fixed the problem!

查看更多
登录 后发表回答