【问题标题】:Access more than one db with ScalaAnorm with Play使用带有 Play 的 ScalaAnorm 访问多个数据库
【发布时间】:2014-11-04 10:55:12
【问题描述】:

如何使用 ScalaAnorm 访问两个独立的 MySQL 数据库?

documentation 似乎只提供了单个数据库访问的示例。

【问题讨论】:

    标签: mysql scala playframework-2.0


    【解决方案1】:

    您可以在 application.conf 中使用它自己的设置为第二个数据库命名(而不是 default):

    db.default.driver=com.mysql.jdbc.Driver
    db.default.url= ...
    db.default.user= ...
    db.default.password= ...
    
    db.anotherdb.driver=com.mysql.jdbc.Driver
    db.anotherdb.url= ...
    db.anotherdb.user= ...
    db.anotherdb.password= ...
    

    然后您可以指定要使用的数据库,如下所示:

    DB.withConnnection("default") { implicit connection =>
        // uses the database named "default"
    }
    
    DB.withConnnection("anotherdb") { implicit connection =>
        // uses the database named "anotherdb"
    }
    

    【讨论】:

      猜你喜欢
      • 2019-12-16
      • 2022-07-22
      • 2015-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-12
      • 2021-08-26
      • 1970-01-01
      相关资源
      最近更新 更多