Pattern for connecting to different databases using JDBC

后端 未结 4 1240
北荒
北荒 2021-02-09 07:33

I\'m writing an application which has to be configurable to connect to Oracle, SQL Server and MySQL depending on client whim.

Up till now I\'d been planning on using the

4条回答
  •  醉酒成梦
    2021-02-09 08:11

    If you need anything complex, Hibernate is a good choice.

    otherwise, what I would do is store your connection details in a properties file (or some other form of configuration) - namely: driver classname, JDBC url, username and password.

    Then, all you need to do is load up the connection details from your properties file and include the correct JAR file on your classpath and you're done.

    You could use a library such as Commons-DBCP if you wanted it to be a little easier to configure but other than that it's all you need to do (provided your SQL statements work on every database, of course).

提交回复
热议问题