-1

Can you say some possible reasons why MySQL would connect to a regular java class, but not to a servlet? Something is not right when I run in tomcat, but as application everything is fine.

Woodchuck
  • 3,869
  • 2
  • 39
  • 70
Sargsyan Grigor
  • 533
  • 1
  • 5
  • 22
  • *"Something is not right"* I agree. Like your question. As in, *what* is not right? *How* is it not right? – Andreas May 07 '16 at 05:16

2 Answers2

1

not sure if this is the problem but maybe MySQL driver is not packaged with your war.

If you are using Eclipse, you could try to: Right button on your project -> Properties -> Deployment Assembly and Add your mysql driver to it

If you are using maven be sure to add that dependency:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>your driver version</version>
</dependency>

Aside from that, is better to include this driver in your Tomcat libraries folder.

Hope it helps.

OscarBcn
  • 626
  • 4
  • 11
0

One of the reasons was jdbc jar file should have also been in tomcat/lib folder, that was my problem.

Sargsyan Grigor
  • 533
  • 1
  • 5
  • 22