pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rob Sargent <robjsargent@gmail.com>
To: Mark Rotteveel <mark@lawinegevaar.nl>
Cc: pgsql-jdbc@lists.postgresql.org
Subject: Re: first connection attempt always fails, subsequent always succeed
Date: Thu, 12 Nov 2020 14:41:57 -0700
Message-ID: <FA9CAFC7-17B8-45F3-8985-F7AC799DABD9@gmail.com> (raw)
In-Reply-To: <20e3d445-8a1b-15c1-39de-d2ff003929d0@lawinegevaar.nl>
References: <98039f46-ab40-2c79-7620-3fa35ecb9869@gmail.com>
	<83C25F63-72BD-484F-94F4-11D996E759D2@gradwell.com>
	<1239978e-d9bc-26d4-23f4-79009462cbae@gmail.com>
	<20e3d445-8a1b-15c1-39de-d2ff003929d0@lawinegevaar.nl>

Bingo.  I have that in one servlet, the writer, whose code pre-dates the readers.  I’ll push that down one class.
Thanks so much.


> On Nov 12, 2020, at 1:42 PM, Mark Rotteveel <mark@lawinegevaar.nl> wrote:
> 
> On 12-11-2020 20:31, Rob Sargent wrote:
>> thinking these forums like bottom posting
>> From my war file (which I explode)
>>    WEB-INF/lib/postgresql-42.2.18.jar
> 
> If the JDBC driver is included in the WAR, then you need to explicitly load the driver with `Class.forName("org.postgresql.Driver")`, because automatic driver loading doesn't work when the driver is on an web application classpath; it will only work if the driver is on the initial classpath (ie in Tomcats lib folder).
> 
> The second attempt likely works because you or your code did something that triggered the driver to load (ie directly or indirectly loading the org.postgresql.Driver class).
> 
> That said, using `DriverManager.getConnection` in a web application is generally not a good idea. For performance it is usually better to use a connection pool (eg the one built-in in Tomcat, or a third-party lib like HikariCP).
> 
> Mark
> -- 
> Mark Rotteveel
> 
> 






view thread (6+ messages)

Message-ID: <FA9CAFC7-17B8-45F3-8985-F7AC799DABD9@gmail.com>
Permalink:  ../FA9CAFC7-17B8-45F3-8985-F7AC799DABD9@gmail.com/
Also on:    postgresql.org/message-id/FA9CAFC7-17B8-45F3-8985-F7AC799DABD9@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: robjsargent@gmail.com, mark@lawinegevaar.nl
  Subject: Re: first connection attempt always fails, subsequent always succeed
  In-Reply-To: <FA9CAFC7-17B8-45F3-8985-F7AC799DABD9@gmail.com>
  References: <98039f46-ab40-2c79-7620-3fa35ecb9869@gmail.com> <83C25F63-72BD-484F-94F4-11D996E759D2@gradwell.com> <1239978e-d9bc-26d4-23f4-79009462cbae@gmail.com> <20e3d445-8a1b-15c1-39de-d2ff003929d0@lawinegevaar.nl> <FA9CAFC7-17B8-45F3-8985-F7AC799DABD9@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox