Skip to content

getDatabaseMajorVersion throws SQLException: "Failed to retrieve server version." #2227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jeloba opened this issue Mar 18, 2025 · 0 comments
Labels

Comments

@jeloba
Copy link

jeloba commented Mar 18, 2025

The database metadata object is throwing exceptions when fetching the server version.

Steps to reproduce

  1. Spin up a fresh Clickhouse test container
  2. Obtain a database connection to it
  3. call connection.getMetadata().getDatabaseMajorVersion()

Expected behaviour

The version should be returned. Using the connection object to fetch version() using a prepared statement works fine.

Code example

    container =
        new ClickHouseContainer("clickhouse/clickhouse-server:22.2");
    container.start();

    try (var c = container.createConnection("?")) {
      // executing the version fetch like this works
      var r = c.prepareStatement("SELECT version() as server_version").executeQuery();
      r.next();
      var v = r.getString("server_version");
      System.out.println(v);

      // this fails
      var v2 = c.getMetaData().getDatabaseMajorVersion();
      System.out.println(v2);
    }

Error log

Caused by: java.sql.SQLException: Failed to retrieve server version.
        at com.clickhouse.jdbc.ConnectionImpl.lambda$getServerVersion$0(ConnectionImpl.java:103)
        at java.base/java.util.Optional.orElseThrow(Optional.java:403)
        at com.clickhouse.jdbc.ConnectionImpl.getServerVersion(ConnectionImpl.java:103)
        at com.clickhouse.jdbc.metadata.DatabaseMetaData.getDatabaseMajorVersion(DatabaseMetaData.java:1188)

Configuration

Environment

  • Client version: jdbc 2
  • Language version: java 21
  • OS: linux

ClickHouse server

  • ClickHouse Server version: 22.2.3.1
@jeloba jeloba added the bug label Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant