0

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.

1 Answer 1

2
  • 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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.