Re: loading jdbc Driver in servlet

From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: Thomas Kellerer <spam_eater(at)gmx(dot)net>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: loading jdbc Driver in servlet
Date: 2018-12-17 11:26:52
Message-ID: CADK3HH+ikPCts044CrSy+4Q=YdFE11XLrpU2bYKjO_thr+_bYw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 17 Dec 2018 at 02:28, Thomas Kellerer <spam_eater(at)gmx(dot)net> wrote:

> 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.
>

Servlet classpath issues are legendary. As Thomas points out setting up the
classpath for a servlet engine is not trivial.

Dave Cramer

davec(at)postgresintl(dot)com
www.postgresintl.com

>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message hamann.w 2018-12-17 12:13:49 conditionally terminate psql script
Previous Message Thomas Kellerer 2018-12-17 07:28:12 Re: loading jdbc Driver in servlet