| From: | Rob Sargent <robjsargent(at)gmail(dot)com> |
|---|---|
| To: | Mark Rotteveel <mark(at)lawinegevaar(dot)nl> |
| Cc: | pgsql-jdbc(at)lists(dot)postgresql(dot)org |
| Subject: | Re: first connection attempt always fails, subsequent always succeed |
| Date: | 2020-11-12 21:41:57 |
| Message-ID: | FA9CAFC7-17B8-45F3-8985-F7AC799DABD9@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-jdbc |
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(at)lawinegevaar(dot)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
>
>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Dave Cramer | 2020-11-13 16:08:29 | [pgjdbc/pgjdbc] ff22a3: feat: implement adaptive fetching (#1718) |
| Previous Message | Mark Rotteveel | 2020-11-12 20:42:07 | Re: first connection attempt always fails, subsequent always succeed |