[2.5.3] choosing other than default datasource from application.conf

12 views
Skip to first unread message

Jakub Błaszczyk

unread,
May 31, 2016, 12:20:47 PM5/31/16
to play-framework
I have three datasurces in application.conf:

db.default.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
db.default.url="jdbc:sqlserver://server1:1433;integratedSecurity=true;database=xyz"

db.csdg.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
db.csdg.url="jdbc:sqlserver://server2:1433;integratedSecurity=true;database=abc"

db.lite.driver=org.sqlite.JDBC
db.lite.url="jdbc:sqlite:/folder/sqlite.db"

in my Application.scala I Have:

class Application @Inject()(db: Database) extends Controller {

def index = Action {

val title = "title - DEMO"
val navbar = "navbar - DEMO"
val listOfClinets = MutableList[Clients]()

val conn = db.getConnection() // I can connect to this datasource with no problems

val stm = conn.createStatement()
val res = stm.executeQuery("select * from table")
while (res.next()) {
listOfClinets.+=(Clients(res.getInt(1), res.getInt(2), res.getString(3)))
}

    conn.close()

    val conn2 = db.getConnection() // how to connect here to csdg or lite datasource?

val stm2 = conn2.createStatement()
val res2 = stm2.executeQuery("select * from table")
while (res2.next()) {
listOfClinets.+=(Clients(res2.getInt(1), res2.getInt(2), res2.getString(3)))
}

conn2.close()

Ok(views.html.index(title)(navbar)(listOfClinets))
}



How to connect in conn2 to different datasource? csdg or lite? I search online but can't figure it out :-( I am just starting out with scala, play and programming so sorry for asking basic question!

- Kuba
Reply all
Reply to author
Forward
0 new messages