1
直到我在我的應用程序中只使用一個數據庫。所以對於任何SQL查詢,我只是使用默認數據庫。下面給出有關數據庫的信息。如何在play-framework中使用默認以外的其他數據庫?
db.default.driver=org.postgresql.Driver
db.default.url="postgres://user:[email protected]:5439/database_name"
這些信息保存在appliction.conf文件中。在下面的代碼中DB是默認的數據庫。
DB.withConnection {
conn =>
{
val statement = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)
try {
statement.execute(sql)
}
catch {
case e: Exception => Logger.debug("There is some error with the database")
}
}
}
但我需要使用另一個數據庫。下面給出有關數據庫的信息。
db.um.driver=com.mysql.jdbc.Driver
db.um.url="mysql://user:[email protected]:3306/database_name"
這些信息也保存在application.conf文件中。現在我如何訪問該數據庫並運行一個sql命令。
非常感謝:D –