开发者

What architecture to follow to connect to multiple databases

开发者 https://www.devze.com 2023-01-08 15:53 出处:网络
Dear All, I\'m building a core java application in which i have say 20 databases an开发者_运维知识库d want to connect to each of them depending upon from where request has come to access which databas

Dear All, I'm building a core java application in which i have say 20 databases an开发者_运维知识库d want to connect to each of them depending upon from where request has come to access which database.

I want to connect to databases only once from where i can pick the connection and return; please suggest what type of architecture to follow.


You have to keep a list of connection pools.

I would use a Map< String, ConnectionPool >, where the key is the connection id. When you need a connection, you take it from this map :

Connection connectionDbAccounts = connectionMap.get("accounts").getConnection();
// Use connectionDbAccounts...
connectionDbAccounts.close();


Use a HashMap<Location, DatabaseConnection> ?

0

精彩评论

暂无评论...
验证码 换一张
取 消