Umesh Kacha
Umesh Kacha

Reputation: 13686

Design approach for multiple database connection like DB2, MySQL etc using JDBC

Hi I have Java application which connects to different databases like DB2, MySQL etc. One way I can think of is in a configuration file we configure databases and create different JDBC Connection objects and connect to the databases.

Is this the best way to achieve this task? Or we can achieve this in a better way with minumum efficient code.

Please guide. Thanks in advance.

Upvotes: 0

Views: 171

Answers (1)

Juned Ahsan
Juned Ahsan

Reputation: 68715

  • Put the details of databases, connections strings, drivers etc in a configuration/properties file.

  • Read that property file on application startup or on first database connection request

  • Implement a factory of connections and use typeofDB as the input to the factory, which will return a connection object for that database using the configuration.

  • You can control the number of connections etc in your factory if you want.

Hope it helps!

Upvotes: 2

Related Questions