I am writing a simple Servlet that uses JDBC to talk to MySQL and deploying it
in Tomcat. Why do I need to add the line -:
Class.forName("com.mysql.jdbc.Driver");
to load the JDBC driver ? If I don’t do this I get an exception of -:
java.sql.SQLException: No suitable driver was found.
Why is it when I use a JDBC connection in Servlets and deploy it in Tomcat must
the class be loaded dynamically ? Why can’t Tomcat do that for me when I have
already added it to the build path ?
From Java 6 onwards there is no need for the JDBC Driver to be loaded
dynamically. So why when using JRE 8 and Tomcat 8 must this be done ?
Cant it be loaded automatically like for normal apps ? It sure would be a lot
more cleaner code.
Regards
Sreyan Chakravarty