gpt4 book ai didi

mysql - 通过 Play 使用 ScalaAnorm 访问多个数据库

转载 作者:行者123 更新时间:2023-11-29 12:43:36 26 4
gpt4 key购买 nike

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

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

最佳答案

您可以在 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"
}

关于mysql - 通过 Play 使用 ScalaAnorm 访问多个数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25771393/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com