Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gYnKC-00082K-NE for pgsql-general@arkaria.postgresql.org; Mon, 17 Dec 2018 07:28:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gYnKB-0000bJ-9m for pgsql-general@arkaria.postgresql.org; Mon, 17 Dec 2018 07:28:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gYnKB-0000bC-1M for pgsql-general@lists.postgresql.org; Mon, 17 Dec 2018 07:28:23 +0000 Received: from [195.159.176.226] (helo=blaine.gmane.org) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gYnK8-0005vS-LI for pgsql-general@postgresql.org; Mon, 17 Dec 2018 07:28:22 +0000 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1gYnHz-0006ta-VX for pgsql-general@postgresql.org; Mon, 17 Dec 2018 08:26:07 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-general@postgresql.org From: Thomas Kellerer Subject: Re: loading jdbc Driver in servlet Date: Mon, 17 Dec 2018 08:28:12 +0100 Lines: 23 Message-ID: <073b915e-6c46-426b-042d-3e269ffccbcc@gmx.net> References: <5182a498-cfde-e7a3-998d-fea79bedaf35@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@blaine.gmane.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 In-Reply-To: <5182a498-cfde-e7a3-998d-fea79bedaf35@gmail.com> Content-Language: en-GB X-Host-Lookup-Failed: Reverse DNS lookup failed for 195.159.176.226 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Rob Sargent schrieb am 14.12.2018 um 19:28: > Using java 1.8, postgresql-42.1.4.jar, embedded tomcat 9 > > It appears to me that I need to make the call > "Class.forName("org.postgresql.Driver)" when the entry is in a > servlet. Is this expected, within a servlet, or is this just /post > hoc ergo propter hoc /at it finest and I changed something else > (wittingly or not). Same code outside of servlet does not need the > forced loading of the class and the manual claims it's not need after > java 1.6 Class.forName() is definitely not needed if the driver's JAR file is included in the classloader of the class requesting a connection. Where exactly did you put the JDBC driver's jar file? And what exactly is your main() method doing? If you look at Tomcat's startup script (catalina.sh or catalina.bat), it's obvious that setting up the claspath isn't that straightforward. My guess is, that that your main() method does something different and does not properly include the driver's jar in the classpath. Thomas