The first thing we need to learn while working with databases is how to connect the application that we will build with the database itself.
In this recipe, we will show you how to configure Lift to connect with the database of our choice. For this recipe, we will use PostgreSQL; however, other databases can also be used:
Start a new blank project.
Edit the
build.sbt
file to add the lift-mapper and PostgreSQL driver dependencies:"net.liftweb" %% "lift-mapper" % liftVersion % "compile", "org.postgresql" % "postgresql" % "9.2-1003-jdbc4" % "compile"
Create a new database.
Create a new user.
Now carry out the following steps to configure a connection with the database:
Add the following lines into the
default.props
file:db.driver=org.postgresql.Driver db.url=jdbc:postgresql:liftbook db.user=<place here the user you've created> db.password=<place here the user password>
Add the following
import
statement in theBoot.scala
...