Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kdKM2-0003Nk-UR for pgsql-jdbc@arkaria.postgresql.org; Thu, 12 Nov 2020 21:42:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kdKM0-0001ZT-Tu for pgsql-jdbc@arkaria.postgresql.org; Thu, 12 Nov 2020 21:42:04 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kdKM0-0001ZL-Lm for pgsql-jdbc@lists.postgresql.org; Thu, 12 Nov 2020 21:42:04 +0000 Received: from mail-io1-xd2c.google.com ([2607:f8b0:4864:20::d2c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kdKLy-0005B9-3S for pgsql-jdbc@lists.postgresql.org; Thu, 12 Nov 2020 21:42:04 +0000 Received: by mail-io1-xd2c.google.com with SMTP id p7so7665050ioo.6 for ; Thu, 12 Nov 2020 13:42:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=CSPlsDSNylORfOgxYRF9+jFv5rtP5Ku4FWJXrYaHppk=; b=q0v/vs8a/vL2XoRdJI1DALwiJKd8kT82iWGvjpM3lShhuCTzrFew+eTwLHtpZqNN7S NchYzOX2zhF77U6WOaBQ7o0rp/teQgMG4Aq/tdMuYnM1/XtNOGhJ7w5CGfGmxFDdjUON lHxTSR8GXpZQ3eGJyHKl2Dw/VtxpUbOIScU/EBYms4pIDbys+OEMd3W83f8zzvrVUa99 x16stgxrukKkhXunx8+Thrvk3teQ+zqwL/jDjihKTgR2cxK2pvkziJv8yj9SAxYKZmLs b+Fl5ebESWP/VwO69kCUSHwa7lqbjmgC6KMzvn1/RtNMXO+5F87lc9zyiqGiI1r1mZHS Y9Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=CSPlsDSNylORfOgxYRF9+jFv5rtP5Ku4FWJXrYaHppk=; b=b9KUT3yEOAenw/rGfa26ZJnwbZbHury8YACaeWNYpkq7WpaKyrud/nvKkCe9MCVEVQ W+VZpQeT2Ivfohb0RsHEGFnUdZYuJZ+p/K0XRJPIm7Sx0SDLk7B1n6jumHoNTybk3fUY P3/xa4MA44JtGRa1Gsybg6fsNeQ9E08mHP3woGQtK+OrBySqptf0LOvNT5cA/AAzQH58 7iP0tjKAg4jbcYM31wnSGunTP49eaVDSkrhw9rjDLPzwHg6Eb0j700Ri3CGfG18vhz0y xht0nQQO7gL6kCZjXyqh+d+nDGprqe8ad35IXsIk8eVjaePOMxzA8EWbYjJdcSXHNOjl 2fKQ== X-Gm-Message-State: AOAM533yDJLjTBn7tgSRLpfnQks7LRQ7Iu+U3dLDnkhNMZyG1pqEQlxd f/OIaGJ7n1rPTe9M/oC7K0iQrrq5two= X-Google-Smtp-Source: ABdhPJw2UKANJb3iOwTZwZxfn2kg811mujHKLzY/qTzG9TxcWX5DR4DKGMaZTNS1wTspjqLYTJk6DA== X-Received: by 2002:a6b:b28d:: with SMTP id b135mr832834iof.95.1605217320008; Thu, 12 Nov 2020 13:42:00 -0800 (PST) Received: from ?IPv6:2601:681:5500:dde0:944f:a828:986f:e93c? ([2601:681:5500:dde0:944f:a828:986f:e93c]) by smtp.gmail.com with ESMTPSA id p24sm3813353ill.59.2020.11.12.13.41.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Nov 2020 13:41:59 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Subject: Re: first connection attempt always fails, subsequent always succeed From: Rob Sargent In-Reply-To: <20e3d445-8a1b-15c1-39de-d2ff003929d0@lawinegevaar.nl> Date: Thu, 12 Nov 2020 14:41:57 -0700 Cc: pgsql-jdbc@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: 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> To: Mark Rotteveel X-Mailer: Apple Mail (2.3608.120.23.2.4) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Bingo. I have that in one servlet, the writer, whose code pre-dates the = readers. I=E2=80=99ll push that down one class. Thanks so much. > On Nov 12, 2020, at 1:42 PM, Mark Rotteveel = wrote: >=20 > On 12-11-2020 20:31, Rob Sargent wrote: >> thinking these forums like bottom posting >> =46rom my war file (which I explode) >> WEB-INF/lib/postgresql-42.2.18.jar >=20 > 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). >=20 > 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). >=20 > 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). >=20 > Mark > --=20 > Mark Rotteveel >=20 >=20