How to use multiple JDBC drivers in the same application?

前端 未结 2 1032
长情又很酷
长情又很酷 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.

提交回复
热议问题