How to use multiple JDBC drivers in the same application?

前端 未结 2 1028
长情又很酷
长情又很酷 2021-01-17 23:01

As far as I understand, as soon as I execute

Class.forName(\"net.sourceforge.jtds.jdbc.Driver\");

I initialize the application to use JTDS

相关标签:
2条回答
  • 2021-01-17 23:27

    You misunderstand. When you load a driver class with Class.forName(), that driver registers itself with the driver manager. You can do this with as many drivers as you want.

    The first parameter of getConnection() is a URL that will uniquely identify the driver to use for that connection.

    However, rather than getting connections directly from the driver manager, I recommend that you use a connection pool (such as Apache DBCP). This will let you get connections on an as-needed basis, and will provide some additional functionality such as warning you if you forget to return the connection to the pool.

    0 讨论(0)
  • 2021-01-17 23:29

    You need to use DataSource. Configure a DataSource for each type of connection and the use the appropriate DataSource each time (e.g. via the proper DAO)

    0 讨论(0)
提交回复
热议问题