Just started using Tomcat 6.0.26 connected to MySQL 5.1.  The MySql server
contains a database for each organization.  Each user that logs in,
specifies an organization and is directed to the corresponding DB.  I would
like to employ connection pooling, with a small pool allocated to each
database.  The application authenticates users, users are not authenticated
at the database level.  Here is the current setup in context.xml:


 <Resource name="jdbc/DB"
              auth="Container"
              type="javax.sql.DataSource"
              maxActive="10"
              maxIdle="5"
              maxWait="10000"
              driverClassName="com.mysql.jdbc.Driver"
              url="jdbc:mysql://localhost:3306" />


Notice no username or password entry exists.  Here's the code to get a
connection:

Context ctx = new InitialContext();
org.apache.tomcat.dbcp.dbcp.BasicDataSource ds =
(org.apache.tomcat.dbcp.dbcp.BasicDataSource)ctx.lookup(
"java:comp/env/jdbc/DB" );

// These must be set before the call to getConnection(), since getConnection
actually creates the pool.
ds.setDefaultCatalog( orgID );
ds.setUsername( orgID );
ds.setPassword( orgID );

try{ connection = ds.getConnection(); }
catch( SQLException e ) ...


My question is, does this accomplish the goal of an efficient connection
pooling mechanism using multiple databases?  Are there glaring errors in the
above config? Is there a better method?


Best Regards,
Andrew

Reply via email to