6

我们的 Java 应用程序(在 Jetty 7.5.4 上运行的 Web 应用程序)使用底层数据库。有多个数据库用户,Java 部分需要使用这些数据库用户访问数据库。我想知道是否有一个数据库连接池库可以让我们使用多个数据库用户访问数据库。我知道有一堆 dbcp 库可以让我们与单个数据库用户一起使用,但我找不到任何支持多个数据库用户的库。

任何帮助表示赞赏,谢谢,婴儿车。

4

2 回答 2

3

Tomcat DBCP 绝对支持多用户(源代码)。我不确定如何配置它,但它已经实现DataSource.getConnection(username, password)了,这是所需的关键功能。

于 2014-03-20T16:18:49.930 回答
2

除了上面 ngreen 的评论,您还需要在数据源属性中将 AlternateUsernameAllowed 设置为 true,但是您仍然需要在属性上设置用户名/密码,因为这是在创建池时使用的。

/**
 * Returns true if the call {@link DataSource#getConnection(String, String) getConnection(username,password)} is
 * allowed. This is used for when the pool is used by an application accessing multiple schemas.
 * There is a performance impact turning this option on.
 * @return true if {@link DataSource#getConnection(String, String) getConnection(username,password)} is honored, false if it is ignored.
 */
public boolean isAlternateUsernameAllowed();
于 2016-05-10T02:30:51.460 回答