Re: first connection attempt always fails, subsequent always succeed

From: Alan Stange <stange(at)rentec(dot)com>
To: Rob Sargent <robjsargent(at)gmail(dot)com>, David Gradwell <david(at)gradwell(dot)com>, "pgsql-jdbc(at)lists(dot)postgresql(dot)org" <pgsql-jdbc(at)lists(dot)postgresql(dot)org>
Subject: Re: first connection attempt always fails, subsequent always succeed
Date: 2020-11-12 20:05:09
Message-ID: d3f3ca50-a77a-72c8-e737-15c5fcce23fd@rentec.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On 11/12/20 2:31 PM, Rob Sargent wrote:
>
>
> On 11/12/20 12:11 PM, David Gradwell wrote:
>>
>> Rob,
>>
>>  
>>
>> If this is obvious apologies, but have you explicitly included an
>> appropriate JDBC driver in your .war build ? 
>> https://jdbc.postgresql.org/download.html
>> <https://jdbc.postgresql.org/download.html>   I am currently fighting
>> issues with MacOS apparently not allowing connections to be made
>> (timeout or host not found) and have reverted to a 9.3 build for testing.
>>
>>  
>>
>> Are you using NetBeans  as your IDE ?
>>
>>  
>>
>> David Gradwell
>>
>>  
>>
>> *From: *Rob Sargent <robjsargent(at)gmail(dot)com>
>> *Date: *Thursday, 12 November 2020 at 18:59
>> *To: *"pgsql-jdbc(at)lists(dot)postgresql(dot)org" <pgsql-jdbc(at)lists(dot)postgresql(dot)org>
>> *Subject: *first connection attempt always fails, subsequent always
>> succeed
>>
>>  
>>
>> This is an embedded tomcat application, not full-blown apache
>> server.  Works great when it does...  I haven't wired in a connection
>> supplier yet since (for now) there are few clients and they do two
>> reads and one write, all very large.
>>
>> java:
>>
>> java -version
>> openjdk version "11.0.9" 2020-10-20
>> OpenJDK Runtime Environment (build 11.0.9+11-Ubuntu-0ubuntu1.20.04)
>> OpenJDK 64-Bit Server VM (build 11.0.9+11-Ubuntu-0ubuntu1.20.04,
>> mixed mode, sharing)
>>
>> tomcat: 
>>
>> version 9.0.39
>>
>> poostgres:
>>
>> PostgreSQL 12.4
>>
>> This is the servlet's connection code:
>>
>> String templateUrl =
>> System./getProperty/("SGSSVR_databaseConnection",
>> "jdbc:postgresql://%s/%s"); ///host(with :port) / dbname/
>>
>> String fullurl = String./format/(templateUrl, dbhost, dbname); 
>> //will add port to this next
>>
>> conn = DriverManager./getConnection/(fullurl, dbrole, magicPassword);
>>
>> dsl = DSL./using/(conn, SQLDialect./POSTGRES/);
>>
>> which generates this stack trace, showing what looks to me like a
>> good url (and which works later).
>>
>> java.sql.SQLException: No suitable driver found for
>> jdbc:postgresql://localhost/version4007
>>     at
>> java.sql/java.sql.DriverManager.getConnection(DriverManager.java:702)
>>
> thinking these forums like bottom posting
>
> From my war file (which I explode)
>
> WEB-INF/lib/postgresql-42.2.18.jar
>
> I get the same behaviour running from within IntelliJ and from
> gradle/command-line, on ubuntu 20.0
>

Do you have a call

Class.forName("org.postgresql.Driver");

in the code to load the postgresql driver into the application?

Alan

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Mark Rotteveel 2020-11-12 20:42:07 Re: first connection attempt always fails, subsequent always succeed
Previous Message Rob Sargent 2020-11-12 19:31:34 Re: first connection attempt always fails, subsequent always succeed