What is the SYSTEM PATH that you are referring to ? Is it the JAVA_HOME or the PATH system variable ?
What is the CLASSPATH just before Tomcat properly starts up ? What is it after it starts up ? Is the same jar files below -: bin/bootstrap.jar bin/tomcat-juli.jar Correct me if I am wrong that means that whatever dependencies I have in my project is not added to the SYSTEM CLASSPATH but is instead loaded by TOMCAT. So if a module searches only the SYSTEM CLASSPATH it won’t be able to find the dependencies. Am I right ? Regards Sreyan Chakravarty From: Christopher Schultz Sent: Wednesday, February 18, 2015 8:30 PM To: Tomcat Users List -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 Sreyan, On 2/18/15 9:25 AM, sreya...@gmail.com wrote: > 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. My guess is that DriverManager only searches the system CLASSPATH which only contains the following JAR files when launching Tomcat using the standard scripts: bin/bootstrap.jar bin/tomcat-juli.jar The bootstrap class then configures a new ClassLoader (including lib/*.jar) for the Tomcat server and Tomcat properly launches using /that/. I think your JDBC driver simply isn't visible to DriverManager's auto-loading. But when you call Class.forName, the driver registers itself with DriverManager, which is okay to do if DriverManager didn't know about your driver. - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: GPGTools - http://gpgtools.org iQIcBAEBCAAGBQJU5KkJAAoJEBzwKT+lPKRYKxEP/RXZTiVXkiIGl2ALwgAgNL/C BjekoBb7b9xoKqm0WBK4mInZ9WW1pEnAkvSDsXyRZ3nrqGBXFtIatehBYo4fFizL W+e7vM8v3C+lruqqSSEPH2Mn2Dx0AO/zT/bu+di+N0Q1ZYWvgWukw1DVoKMacZAN 23dmkR62IbfwprnZ83hWhJimIe926EpooMJ+ZgaccKxTdIPHo6RNJBnsFdiTr2o4 ZqtF/8m4ShDipAyF8fmhsa4w3rEUYsgV1CN+tjDtSEpJ9irTMCEZY3tHlElUhNgR rg9XlkHGH+9WufJeGujZEndG3x9ey0tZM8jxm5kmty2G9w3hq12EavncH9/JyjCk fdUX/xMLgwZQWDMPvgqgZeH8+jgYhdbDY+RTPTTCLulu+Qy6uz+/ijjPGX/dUtez NSIXFgMu7j0tzLU3Z2FIdTvZlI9SpotndQ34ddT4HBqo35ooJw7fwDCeh/SW3UMm IaUxdzroRRksY5TU2ZqifcF3m2cKUxXX5O454nSa0z2DdWCBe7JM2cEKPP1NNn4L uiEBxt/7VWCl4ZIrZcqjXn6IHG2lYyeTpYL+x+KUUpgEwOZnSlbOyWTje2FJ6UNb K7RIR3ITGyMDXnpAgFnt45jStCSkqHilI+ru3WplD3aEJf3xN+c9i9t6EAZrq04C eK2ta2Y6JGU3JuKoazol =06fK -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org