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.
Connection mysqlCon = DriverManager. getConnection(mysqlUrl, "root", "password"); To connect to multiple databases in a single JDBC program you need to connect to the two (or more) databases simultaneously using the above steps.
Connection pooling is a technique of creating and managing a pool of connections that are ready for use by any thread that needs them. Connection pooling can greatly increase the performance of your Java application, while reducing overall resource usage.
A JDBC connection pool is a group of reusable connections for a particular database. Because creating each new physical connection is time consuming, the server maintains a pool of available connections to increase performance. When an application requests a connection, it obtains one from the pool.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With