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 (ie 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?
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")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.