Make java client lib accept same connection strings as psql - Mailing list pgsql-hackers

From Michael Leonhard
Subject Make java client lib accept same connection strings as psql
Date
Msg-id CAHnQ7HO7HeB2gPqHuiNRidh7mQWAsO8t=Fwa=GC21tb9aY3Msw@mail.gmail.com
Whole thread Raw
Responses Re: Make java client lib accept same connection strings as psql
List pgsql-hackers
Hi PostgreSQL Hackers,
I've run into something confusing.  The psql command accepts
connection strings of the form:

postgresql://user1:pass1@localhost:5432/db1?sslmode=require

But passing this string to the java client library (with a "jdbc:"
prefix) fails.  See the exception and stack trace below.  According to
the docs https://jdbc.postgresql.org/documentation/80/connect.html ,
the java client library accepts connection strings with this form:

postgresql://localhost:5432/db1?user=user1&password=pass1&ssl=true

How about making the Java client library accept the same connection
strings as psql and other command-line tools?  That would make
PostgreSQL easier to use and increase its popularity.

Sincerely,
Michael

Exception in thread "main" org.postgresql.util.PSQLException: The
connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:292)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:211)
at org.postgresql.Driver.makeConnection(Driver.java:458)
at org.postgresql.Driver.connect(Driver.java:260)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
at org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:98)
at org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:83)
at com.leonhardllc.x.db.temp.TemporaryDatabase.createTempDatabase(TemporaryDatabase.java:39)
at com.leonhardllc.x.db.generated.JOOQSourceGenerator.main(JOOQSourceGenerator.java:35)
Caused by: java.net.UnknownHostException: user1:pass1@localhost
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:220)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)
at java.base/java.net.Socket.connect(Socket.java:591)
at org.postgresql.core.PGStream.<init>(PGStream.java:75)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:91)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192)
... 10 more



pgsql-hackers by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: Parallel copy
Next
From: Joe Nelson
Date:
Subject: Re: POC: rational number type (fractions)