Subject: [pgjdbc/pgjdbc] issue #2694: the url is invalid

From: "ivostoykov (@ivostoykov)" <[email-masked]>
Date: Mon, 05 Dec 2022 22:21:04 +0000

**I'm submitting a potential issue**

  <!--- What kind of an issue is this? Put an `x` in all the boxes that apply: -->
- [x] bug report
- [ ] feature request

**Describe the issue**
Trying to connect the free db hosting located on db.bit.io using a SQL IDE client.  I've got a connection string error.

**Driver Version?**  42.5.1

**Java Version?** 11.0.11+9-Ubuntu-0ubuntu2.18.04

**OS Version?** Linux Ubuntu 22.04 LTS

**PostgreSQL Version?** 14

**To Reproduce**
Using a connection string URL like postgresql://aaa:[email-masked]/aaa/bbb
**aaa/bbb** is the name of the database. At the same time **aaa** is the username as well

**Expected behaviour**
to connect aaa/bbb databse
But got an error "_According to the driver "PostgreSQL", the URL "postgresql://aaa:[email-masked]/aaa/bbb" is invalid._"

This text of the error is reported by the Squirrel SQL client I'm using to connect
Tried to set the driver properties individually, bypassing the query string parsing. But the connection still fails.
No problem to connect using **pg** library in NodeJs with the same credentials. 

**Logs**
no PostgreSQL logs are available

---

From: "davecramer (@davecramer)" <[email-masked]>
Date: Tue, 06 Dec 2022 15:45:28 +0000

JDBC doesn't use this particular form.

Use ```
jdbc:postgresql:[//host[:port]/][database][?property1=value1[&property2=value2]...]
```
you can specify the user and password in the properties.

---

From: "ivostoykov (@ivostoykov)" <[email-masked]>
Date: Tue, 06 Dec 2022 18:13:18 +0000

Hi @davecramer ,
Thank you for the answer. I believe you missed the point (perhaps I'm wrong).
And as I see it is that the **database name contains a slash in it**

Thank you

PS: It is a pity the case is closed without additional discussion.

---

From: "davecramer (@davecramer)" <[email-masked]>
Date: Wed, 07 Dec 2022 02:56:25 +0000

ah, ok, I can take a look tomorrow. Thanks for the extra information

---

From: "fladi (@fladi)" <[email-masked]>
Date: Thu, 20 Feb 2025 19:13:55 +0000

I was hit by the same issue, our databases follow the convention:

- `vhost-1.example.com/production`
- `vhost-1.example.com/testing`
- `vhost-1.example.com/feature-1234`
- `vhost-2.example.com/production`
- ...

Now someone wants to connect to them via JDBC (42.7.5) and is hit with `Unable to parse URL jdbc:postgresql://db.example.com:5432/vhost-1.example.com/testing`. I tried to use RFC3986 as stated in the documentation but this only resulted in the same error (with `%2F` decoded to "`/`").

JDBC was used within DBeaver.

---

From: "davecramer (@davecramer)" <[email-masked]>
Date: Thu, 20 Feb 2025 19:22:11 +0000

I just tried 
```
public class TestDBNameWithSlash {
    public static void main(String[] args) {
        try (Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/abc%2fdef", "test", "test")) {
            System.out.println(con.getCatalog());
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
```
and it worked fine.

---

From: "fladi (@fladi)" <[email-masked]>
Date: Thu, 20 Feb 2025 19:34:55 +0000

You are right, I created a new Connection in DBeaver using `%2f` and now it worked. For my first attempt I created a connection with `/` in the DB name and only changed it to `%2f` once I saw the remark in the documentation. So it is more of a DBeaver issue that it kept the original DB name somewhere.

---

From: "nsidhaye (@nsidhaye)" <[email-masked]>
Date: Mon, 10 Nov 2025 04:20:00 +0000

I think DB driver automatically encode URL so client do not need to encode it while configuring. May be we can add some parameter like `encode`