java如何连接不同的数据库,如何在java中为不同的数据库创建多个数据库连接

I have an application which uses four databases in different geographical locations. All the databases contains same tables and only the database name is different according to the location.

I have to create some reports in my application which uses data from each database. What would be the proper way to create those database connection from a java application and is there a suitable design pattern for this task which I could use?

解决方案

As you have not tagged your question with any of this, hibernate, JPA, ORM, I assume you are dealing with plain JDBC.

Having said that, I suggest you to have a DAO layer to deal with underlying databases, and leave the connection details to specific implementations. You can configure your connection strings in some .properties files, lets say.

[Complement]

You can also make use of DAO factory, an implementation of Abstract Factory or Factory Method pattern, whichever suits here.

[Links]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值