简体   繁体   中英

Java based Database Connection Pool library for multiple database users

Our Java application (web application that runs on Jetty 7.5.4) uses an underlying database. There are multiple databases users and the Java part needs to access the DB using those database users. Am wondering if there is a database connection pool library that lets us access the DB with multiple database users. I know there are a bunch of dbcp libraries that lets us use with single database user, but am unable to find any library that supports multiple database users.

Any help is appreciated, Thanks, Pram.

Tomcat DBCP definitely supports multiple users ( source code ). I'm not exactly sure how to configure it, but it has implemented DataSource.getConnection(username, password) , which is the key feature needed.

In addition to ngreen's comment above, you also need to set AlternateUsernameAllowed to true in your data source properties, however you still need to set a username / password on the properties as this is used when the pool is created.

/**
 * 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM