Pattern for connecting to different databases using JDBC

后端 未结 4 1229
北荒
北荒 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条回答
  •  梦毁少年i
    2021-02-09 08:08

    Take a look at Datasource. This is the preferred mechanism for obtaining a database connection.

    IMO this provides an adminstrator the greatest flexibility for choosing database, connection pooling, and transaction strategies.

    If you're using tomcat, then see here for how to register a Datasource with tomcat's JNDI.

    If you're using Spring, then you can obtain a Datasource using jee:jndi-lookup.

    If you're using Spring, but don't want to use JNDI, take a look at DriverManagerDataSource for a discussion of how to obtain a pooled Datasource (DBCP or C3P0).

提交回复
热议问题