Skip to content

Commit 76e757a

Browse files
author
Paultagoras
committed
Simplify version fetching
1 parent ddec37a commit 76e757a

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.clickhouse.client.api.Client;
44
import com.clickhouse.client.api.data_formats.ClickHouseBinaryFormatReader;
5+
import com.clickhouse.client.api.query.GenericRecord;
56
import com.clickhouse.client.api.query.QueryResponse;
67
import com.clickhouse.client.api.query.QuerySettings;
78
import com.clickhouse.jdbc.internal.JdbcConfiguration;
@@ -67,16 +68,10 @@ public void setDefaultQuerySettings(QuerySettings settings) {
6768
}
6869

6970
private String getServerVersion() throws SQLException {
70-
try (QueryResponse response = client.query("SELECT version()").get(30, TimeUnit.SECONDS)) {
71-
// Create a reader to access the data in a convenient way
72-
ClickHouseBinaryFormatReader reader = client.newBinaryFormatReader(response);
73-
// Read the next record from stream and parse it as a string
74-
reader.next();
75-
return reader.getString(0);
76-
} catch (Exception e) {
77-
log.error("Failed to retrieve server version.", e);
78-
throw new SQLException("Failed to retrieve server version.", e);
79-
}
71+
GenericRecord result = client.queryAll("SELECT version() as server_version").stream()
72+
.findFirst().orElseThrow(() -> new SQLException("Failed to retrieve server version."));
73+
74+
return result.getString("server_version");
8075
}
8176

8277
public int getMajorVersion() throws SQLException {

0 commit comments

Comments
 (0)