How to get data from another data base in runtime

霸气de小男生 提交于 2020-01-06 04:35:12

问题


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).


回答1:


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"

and to use Groovy dynamic method invocation to call it

def zipCode = ZipCode.'${database}'.get(42)
…
zipCode.'${database}'.save()


来源:https://stackoverflow.com/questions/12235656/how-to-get-data-from-another-data-base-in-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!