如何在运行时从另一个数据库获取数据 [英] How to get data from another data base in runtime
本文介绍了如何在运行时从另一个数据库获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一种最佳的方式来在运行时更改数据库,无论是从休眠状态还是从JNDI或其他方式。当用户单击特定按钮时,我需要更改数据库(更改事件的依存关系)。
I need an optimal way to change Database in run-time, whether from hibernate or from JNDI or another. I need to change the database when a user clicks on a specific button (Change dependencies on events).
推荐答案
如果正在运行在Grails 2.x中,您可以使用 Burt Beckwith的数据源插件。 href = http://grails.org/doc/latest/guide/conf.html#multipleDatasources rel = nofollow>该功能已添加到核心。
If you are running Grails 1.3.x you can to use the Burt Beckwith's Datasources plugin, in Grails 2.x that feature has been added to core.
然后您可以使用参数传递数据库连接名称
Then you can to use a parameter to pass database connection name
def database = params.database
if(!database) database = "default"
并使用调用Groovy动态方法来调用它
def zipCode = ZipCode.'${database}'.get(42)
…
zipCode.'${database}'.save()
这篇关于如何在运行时从另一个数据库获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文