tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: tomcat only query localhost database
Date Thu, 05 Feb 2009 23:05:41 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mihamina,

Mihamina Rakotomandimby (R12y) wrote:
>     catch(Exception e)
>         {
>             try
>                 {
>                     Class.forName("org.gjt.mm.mysql.Driver");
>                 }
>             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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmLcMUACgkQ9CaO5/Lv0PA+xgCeOvylBPgCP154lzEURSQY63jI
V1IAni9VgFA7Pyu1AOME1rX16FPZLlYo
=fryH
-----END PGP SIGNATURE-----

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


Mime
View raw message