Skip to content

Commit 8c1731a

Browse files
author
Paultagoras
committed
Update ConnectionImpl.java
1 parent c1478f9 commit 8c1731a

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

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

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,31 +54,37 @@ public class ConnectionImpl implements Connection, JdbcV2Wrapper {
5454
private final com.clickhouse.jdbc.metadata.DatabaseMetaData metadata;
5555

5656
public ConnectionImpl(String url, Properties info) throws SQLException {
57-
log.debug("Creating connection to {}", url);
58-
this.url = url;//Raw URL
59-
this.config = new JdbcConfiguration(url, info);
60-
this.onCluster = false;
61-
this.cluster = null;
62-
String clientName = "ClickHouse JDBC Driver V2/" + Driver.driverVersion;
63-
64-
if (this.config.isDisableFrameworkDetection()) {
65-
log.debug("Framework detection is disabled.");
66-
} else {
67-
String detectedFrameworks = Driver.FrameworksDetection.getFrameworksDetected();
68-
log.debug("Detected frameworks: {}", detectedFrameworks);
69-
clientName += " (" + detectedFrameworks + ")";
70-
}
71-
72-
this.client = this.config.applyClientProperties(new Client.Builder())
73-
.setClientName(clientName)
74-
.build();
75-
this.client.loadServerInfo();
76-
this.schema = client.getDefaultDatabase();
77-
this.defaultQuerySettings = new QuerySettings()
78-
.serverSetting(ServerSettings.ASYNC_INSERT, "0")
79-
.serverSetting(ServerSettings.WAIT_END_OF_QUERY, "0");
57+
try {
58+
log.debug("Creating connection to {}", url);
59+
this.url = url;//Raw URL
60+
this.config = new JdbcConfiguration(url, info);
61+
this.onCluster = false;
62+
this.cluster = null;
63+
String clientName = "ClickHouse JDBC Driver V2/" + Driver.driverVersion;
64+
65+
if (this.config.isDisableFrameworkDetection()) {
66+
log.debug("Framework detection is disabled.");
67+
} else {
68+
String detectedFrameworks = Driver.FrameworksDetection.getFrameworksDetected();
69+
log.debug("Detected frameworks: {}", detectedFrameworks);
70+
clientName += " (" + detectedFrameworks + ")";
71+
}
8072

81-
this.metadata = new com.clickhouse.jdbc.metadata.DatabaseMetaData(this, false, url);
73+
this.client = this.config.applyClientProperties(new Client.Builder())
74+
.setClientName(clientName)
75+
.build();
76+
this.client.loadServerInfo();
77+
this.schema = client.getDefaultDatabase();
78+
this.defaultQuerySettings = new QuerySettings()
79+
.serverSetting(ServerSettings.ASYNC_INSERT, "0")
80+
.serverSetting(ServerSettings.WAIT_END_OF_QUERY, "0");
81+
82+
this.metadata = new com.clickhouse.jdbc.metadata.DatabaseMetaData(this, false, url);
83+
} catch (SQLException e) {
84+
throw e;
85+
} catch (Exception e) {
86+
throw new SQLException("Failed to create connection", ExceptionUtils.SQL_STATE_CONNECTION_EXCEPTION, e);
87+
}
8288
}
8389

8490
public QuerySettings getDefaultQuerySettings() {

0 commit comments

Comments
 (0)