I need to manage connections to multiple databases in my web app. following are facts regarding the current implementation:
1- I use Tomcat
2- databases are
The MySQL JDBC driver allows omitting the database name from the connection URL as follows:
jdbc:mysql://localhost:3306
You only need to specify the database by Connection#setCatalog() or directly in the SQL queries. See also its reference documentation:
If the
database
is not specified, the connection will be made with no default database. In this case, you will need to either call thesetCatalog()
method on theConnection
instance or fully specify table names using the database name (that is,SELECT dbname.tablename.colname FROM dbname.tablename...
) in your SQL. Not specifying the database to use upon connection is generally only useful when building tools that work with multiple databases, such as GUI database managers.
This allows you for creating a single and reuseable connection pooled datasource in Tomcat. You'll perhaps only need to rewrite your connection manager and/or SQL queries.
There are enough connection pooling framework in the open. Proxool is definitely among the best. Its pretty flexible and easy to use.