Make java client lib accept same connection strings as psql

From: Michael Leonhard <michael(at)leonhardllc(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Make java client lib accept same connection strings as psql
Date: 2020-02-22 01:08:47
Message-ID: CAHnQ7HO7HeB2gPqHuiNRidh7mQWAsO8t=Fwa=GC21tb9aY3Msw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi PostgreSQL Hackers,
I've run into something confusing. The psql command accepts
connection strings of the form:

postgresql://user1:pass1(at)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(at)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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Joe Nelson 2020-02-22 01:24:47 Re: POC: rational number type (fractions)
Previous Message Tomas Vondra 2020-02-22 00:28:02 Re: Parallel copy