How to create multiple database connections for different databases in java

前端 未结 6 1050
心在旅途
心在旅途 2020-12-25 08:31

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

6条回答
  •  隐瞒了意图╮
    2020-12-25 08:38

    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]

    • A very fine implementation of DAO and DAO Factory, by BalusC
    • Core J2EE Patterns -- arguably dated but might provide some idea.

提交回复
热议问题