You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Joji V J <jo...@jojees.net> on 2011/05/11 09:15:34 UTC

Override Driver Manager (DB Connections) through tomcat servers

Hello Friends,

  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..


Thanks,
Joji VJ

Re: Override Driver Manager (DB Connections) through tomcat servers

Posted by Joji V J <jo...@jojees.net>.
Thank you Christopher,

   I'll put it up, verify and let you know on the same!! Once again Thanks!


On Wed, May 11, 2011 at 7:07 PM, Christopher Schultz <
chris@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Joji,
>
> 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
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk3KkSAACgkQ9CaO5/Lv0PCtVgCgqxvcAo12JU0P4pJXtzlV4yBK
> R5cAnjzh6BDKyG1W4/DBtS1Cz6MUzHHt
> =OUDy
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Override Driver Manager (DB Connections) through tomcat servers

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Joji,

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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3KkSAACgkQ9CaO5/Lv0PCtVgCgqxvcAo12JU0P4pJXtzlV4yBK
R5cAnjzh6BDKyG1W4/DBtS1Cz6MUzHHt
=OUDy
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org