tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: tomcat only query localhost database
Date Thu, 05 Feb 2009 23:05:41 GMT
Hash: SHA1


Mihamina Rakotomandimby (R12y) wrote:
>     catch(Exception e)
>         {
>             try
>                 {
>                     Class.forName("");
>                 }
>             catch (ClassNotFoundException e1)
>                 {
>                     e1.printStackTrace();
>                 }
>             Connection con =
> DriverManager.getConnection("jdbc:mysql://localhost/baseName",
>                                             "login",
>                                             "password");
>             con.setAutoCommit(false);
>             return con;
>         }

I know you said "it's in a catch block so it's not the problem, but I
think your statement makes too many assumptions: primarily, that nothing
else is going wrong. You aren't logging any Exceptions caught by that
catch block, so you'd never know that the standard way of getting the
connection (using JNDI) isn't working.

For instance, if your JNDI DataSource isn't set up properly (which is my
guess), your code falls-back to using a Connection obtained from the
DriverManager and points to localhost.

I would argue that this is a stupid way to handle exceptions in your
getConnection method, but who am I to judge?

Anyhow, I suspect that you DO have a problem in your JNDI configuration
and that your code IS falling-back on the localhost JDBC connection. The
fact that it works on another system probably means that you have JNDI
properly configured there.

Try adding some logging statements to that catch block and I think
you'll find that you are silently swallowing an exception and then
getting a localhost connection instead.

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


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

View raw message