-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Anup,

On 2/21/2011 10:20 AM, Anup Niroula wrote:
> Hi,
> out.println ("Cannot connect to database server message "+e.getMessage());
> "This gives following error msg:
> "Cannot connect to database server com.mysql.jdbc.Driver."

How about e.printStackTrace()? Post the entire message and full stack trace.

I can see a whole bunch of things wrong with your original code:

1. You re-register the driver for every request (Class.forName) which
   isn't that big of a deal... just a waste of time at least for the
   MySQL driver. It's mostly just bad coding practice.

2. You create a new Connection for every request. You would be much
   better off using pooled connections. Look at the Tomcat documentation
   for using JNDI DataSources.

3. You swallow nearly all exceptions. At least log them.
   System.err/System.out doesn't count.

4. You shouldn't have any Java code in a JSP (debatable).

5. Everything is hard-coded. Of course, this looks like a test page
   so you can be excused for that :)

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1kFrEACgkQ9CaO5/Lv0PC62QCeIpgG7Wu3fZNcNKfsm+5Mxn4w
3RwAniITH/47q9NrkdiqZK2CgPJWUhFA
=+hIO
-----END PGP SIGNATURE-----

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

Reply via email to