tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: Override Driver Manager (DB Connections) through tomcat servers
Date Wed, 11 May 2011 13:37:36 GMT
Hash: SHA1


On 5/11/2011 3:15 AM, Joji V J wrote:
> Since few days I've noticed that some of the applications in the server
> are using the device manager based database connections, causing too many
> open connections with the database. Unfortunately I'm in no position to
> instruct them to use the tomcat based datasource connections. So here it'll
> of great help if you can provide me with configurations/tips to override the
> java device manager based connections and pass them through the tomcat
> resource driven datasource connections..

I can only think of one way to do this, and it requires the use of a
SecurityManager (which may be more complicated than it's worth for you).
Here's what you do:

1. Go into the class where you /want/ programmers to be able to obtain
connections. Let's call that class ConnectionFactory, and assume there's
a method called getConnection in it. Add this code:

   public Connection getConnection()
     throws ...

       if(null != System.getSecurityManager())
         return AccessController.doPrivileged(
             new PrivilegedAction<Connection>() {
               public Connection run() {
                 // get your Connection object

                 return the_connection;
       } else {
         // get your Connection object

2. Adjust your policy file such that the above code is allowed to make
outgoing connections to your db.

This ought to cause SecurityExceptions to be thrown whenever the
DriverManager is used directly to obtain a connection.

- -chris
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla -


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message