Reputation: 1081
I inject JDBC Database Connections
in Play for Scala to use in web applications as explained here:
This is the declaration I use:
class ScalaControllerInject @Inject()(db: Database) extends Controller {
// rest of the code...
What I need is to inject the JDBC Database Connection in a standalone Play for Scala application (i.e. there's no Controller), like so:
object Main extends App {
val db: Database = // ... get database
val conn = db.getConnection()
// .... rest of the code
}
Is this possible?
Upvotes: 0
Views: 266
Reputation: 2448
You can just create one (Postgres example):
val dbUrl = "jdbc:postgresql://localhost:5432/databaseName?user=username&password=yourpassword"
val database = Databases("org.postgresql.Driver",dbUrl,"testingzzz")
Upvotes: 2