-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Keith,

On 8/17/17 4:02 AM, Sun, Keith wrote:
> Hello ,
> 
> I met mysql jdbc load issue in Tomcat servlet , I also pasted the
> content in this stackoverflow
> <https://stackoverflow.com/questions/45725610/tomcat-jdbc-drivermanage
r-initial-load-issue>
> .
> 
> 
> 
> I finally found this code snippet in the tomcat70
> code<https://github.com/apache/tomcat70/blob/c1a62522e9a6cd6625f026e41
97b490ef1beaa78/java/org/apache/catalina/core/JreMemoryLeakPreventionLis
tener.java>
> and did the debug in eclipse. The classloader to load DriverManager
> is always the AppClassLoader which contains only the bootstrap.jar
> and tomcat-juli.jar on the CLASSPATH only (under
> ${catalina.home}/bin . So my servlet has to manually call
> Class.forName("com.mysql.jdbc.Driver") , otherwise the call to
> DriverManager.getConnection("jdbc:mysql://xxx") will throw "no
> suitable driver found" exception. My questions: 1.      is my
> understanding true ? 2.      The manual or the stackoverflow said
> put the mysql-connector.jar under ${catalina.home}/lib which will
> be initialized once and should work for the DriverManager case. Is
> it not correct now ? try { // Use the system classloader as the
> victim for all this // ClassLoader pinning we're about to do. 
> Thread.currentThread().setContextClassLoader( 
> ClassLoader.getSystemClassLoader());
> 
> /* * First call to this loads all drivers in the current class *
> loader */ if (driverManagerProtection) { 
> DriverManager.getDrivers(); } My enviroment:
> 
> C:\Users\xxxx\Desktop\Tools\apache-tomcat-7.0.78-windows-x64\apache-to
mcat-7.0.78\bin>version.bat
>
> 
Using CATALINA_BASE:
"C:\Users\aisun\Desktop\Tools\apache-tomcat-7.0.78-windows-x64\apache-to
mcat-7.0.78"
> Using CATALINA_HOME:
> "C:\Users\aisun\Desktop\Tools\apache-tomcat-7.0.78-windows-x64\apache-
tomcat-7.0.78"
>
> 
Using CATALINA_TMPDIR:
"C:\Users\aisun\Desktop\Tools\apache-tomcat-7.0.78-windows-x64\apache-to
mcat-7.0.78\temp"
> Using JRE_HOME:        "C:\Program Files\Java\jdk1.8.0_131" Using
> CLASSPATH:
> "C:\Users\aisun\Desktop\Tools\apache-tomcat-7.0.78-windows-x64\apache-
tomcat-7.0.78\bin\bootstrap.jar;C:\Users\aisun\Desktop\Tools\apache-tomc
at-7.0.78-windows-x64\ap
>
> 
Server version: Apache Tomcat/7.0.78
> Server built:   May 10 2017 15:02:19 UTC Server number:  7.0.78.0 
> OS Name:        Windows 7 OS Version:     6.1 Architecture:
> amd64 JVM Version:    1.8.0_131-b11 JVM Vendor:     Oracle
> Corporation 
> C:\Users\aisun\Desktop\Tools\apache-tomcat-7.0.78-windows-x64\apache-t
omcat-7.0.78\bin>

The
> 
bottom line is that your JDBC library JAR should be in
CATALINA_BASE/lib (instance directory) or CATALINA_HOME/bin
(installation directory).

Since you have a unified install/instance directory, your Connector/J
JAR file should be in
C:\Users\aisun\Desktop\Tools\apache-tomcat-7.0.78-windows-x64\apache-tom
cat-7.0.78\lib

Are you using a container-managed JNDI resource (a <Resource> in your
context.xml file), or are you trying top establish your own Connection
by using the DriverManager directly?

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAlmVqBIACgkQHPApP6U8
pFhNxw//ROPjjEN3nTvPZG7CJK3wdfwHaKfqeoO6nJW0Dzl2hgtXBRe+XiBoUdFC
Va5IayzVt8KhCNG5ANIzpRMExi8uvUQnxNEDOzIvCVxCjt8P6Cc+eziUVTLzQ06H
Upw0iuWz83mAdgSsxKWtH6dM46VBAvp/WhMq5mS0ZrE2by0EZSVW0pgwMJMsN4in
OMjnhdUDyJ2hAdLdCEpO0CFG71ab51Ml5oJ05wfGpf3+BVXNqKm3Ec3/1isFEYnC
yYG1Wkuq6ukosTw+Sq9B7CtRPxf/QP08GQOKc/IUFW7wlsUghP6vPMxZNoLdnF7z
YaPsj5mBHvxfCtvde8Q4OM0V5eTyE6U5de0YE3WosRK5ATZS8P8j+/Fl9pa4vIhh
m9wdB6U0xDPA6IvpQfC2B7zJS5OtSmEn01NBfXLhwMcrocyz0M4Up8NGhqO8hbt2
jbCGIyNnpD/yw3+fQV/TL6zu81vT6+OFPAKtsr8yNmwYiyAfyf50feKyJ2HmZXHi
Za3xAXbOdKLaQ0irQI2P6AbyRZXkc8ErI7rX+hFwL9CS1qzFovKN6Mbz3LbR5/R3
feWJP0EH5ySRIDhd3FkmLkqiqJBi8wtSgtkusNAv1x8NmI9SjAIaYLO7gOIZ9z3Z
ZswfsZ+YLOryPHw98Maya0Nx1GCVKqbL5IQtwP705hJnr8xoOOs=
=hOjq
-----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