Skip to content

Allow hostless MySQL JDBC TC URLs - #1

Closed
linghengqian with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-jdbc-url-requirements
Closed

linghengqian with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-jdbc-url-requirements

Conversation

Copilot AI commented Jan 14, 2026 •

Copy link
Copy Markdown

The MySQL JDBC Testcontainers URL parser wrongly treated a leading slash as a hostname, forcing users to add a fake host (e.g., jdbc:tc:mysql:5.7.12://hostname/...). This enables hostless URLs like jdbc:tc:mysql:5.7.12:///mydatabase, consistent with other JDBC modules.

  • Parsing
    • Tightened the DB instance regex to ignore leading /, preventing it from being misread as a hostname for MySQL JDBC URLs.
  • Verification
    • Added a MySQL driver test asserting jdbc:tc:mysql:8.0.36:///databasename starts correctly and selects the expected database.

Example:

String url = "jdbc:tc:mysql:8.0.36:///databasename";
try (Connection conn = DriverManager.getConnection(url)) {
    try (ResultSet rs = conn.createStatement().executeQuery("SELECT DATABASE()")) {
        rs.next();
        // returns "databasename"
    }
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • ge.testcontainers.org
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -Xmx2g -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.14.3-all/10utluxaxniiv4wxiphsi49nj/gradle-8.14.3/lib/gradle-daemon-main-8.14.3.jar (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

According to testcontainers#4121, the testcontainers-mysql module cannot use JDBC URLs like jdbc:tc:mysql:5.7.12:///mydatabase; a custom hostname must be added. However, other modules' JDBC URLs do not require a custom hostname. Please diagnose and fix this.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: linghengqian <20187731+linghengqian@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix JDBC URL for testcontainers-mysql module Allow hostless MySQL JDBC TC URLs Jan 14, 2026
Copilot AI requested a review from linghengqian January 14, 2026 07:51

@linghengqian linghengqian left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@linghengqian
linghengqian deleted the copilot/fix-jdbc-url-requirements branch October 16, 2026 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants