How to configure lift with PostgreSQL

From Lift

Jump to: navigation, search

Lift installs Apache Derby database by default. While that's fine for development work, in production many developers might prefer a more robust and full-featured database. PostgreSQL is a good choice.

To use PostgreSQL instead of Derby, first download and install PostgreSQL, then create a database for your project.

Next edit bootstrap.liftweb.Boot.scala:

object DBVendor extends ConnectionManager {

  def newConnection(name: ConnectionIdentifier): Can[Connection] = {
    try {
      Class.forName("org.postgresql.Driver")
      val dm = DriverManager.getConnection("jdbc:postgresql://localhost/dbname","username", "password")
      Full(dm)
    } catch {
      case e : Exception => e.printStackTrace; Empty
    }
  }

  def releaseConnection(conn: Connection) {conn.close}

}

Replace dbname with the name of your database. Then replace username and password with the username and password, respectively, that you use to connect to the database.

That should work.

Personal tools