I have a class A which connects to mysql database in my localhost. It works fine in eclipse.
Then I modified the project to call/invoke class A from a servlet and deployed to tomcat.
I am getting this exception:
No suitable driver found for jdbc:mysql://localhost:3306/a
and this exception occurs at:
DriverManager.getConnection(connectionUrl, user, password);
What is going wrong here? And how can I fix this problem?
Add:
I'm sure the .jar is under WEB-INF/lib, and this is not the problem.
I just figured it out and the problem is that I forgot to add this line:
Class.forName("com.mysql.jdbc.Driver");
Is there anybody knows that why this line is a must in a web application and not in a java project?