11package com .clickhouse .jdbc ;
22
33import com .clickhouse .client .api .Client ;
4+ import com .clickhouse .client .api .ClientConfigProperties ;
45import com .clickhouse .client .api .internal .ServerSettings ;
56import com .clickhouse .client .api .query .GenericRecord ;
67import com .clickhouse .client .api .query .QuerySettings ;
@@ -50,6 +51,7 @@ public class ConnectionImpl implements Connection, JdbcV2Wrapper {
5051 protected String cluster ;
5152 private String catalog ;
5253 private String schema ;
54+ private String appName ;
5355 private QuerySettings defaultQuerySettings ;
5456
5557 private final com .clickhouse .jdbc .metadata .DatabaseMetaData metadata ;
@@ -62,14 +64,27 @@ public ConnectionImpl(String url, Properties info) throws SQLException {
6264 this .config = new JdbcConfiguration (url , info );
6365 this .onCluster = false ;
6466 this .cluster = null ;
67+ this .appName = "" ;
6568 String clientName = "ClickHouse JDBC Driver V2/" + Driver .driverVersion ;
6669
70+ Map <String , String > clientProperties = config .getClientProperties ();
71+ if (clientProperties .get (ClientConfigProperties .CLIENT_NAME .getKey ()) != null ) {
72+ this .appName = clientProperties .get (ClientConfigProperties .CLIENT_NAME .getKey ()).trim ();
73+ clientName = this .appName + " " + clientName ; // Use the application name as client name
74+ } else if (clientProperties .get (ClientConfigProperties .PRODUCT_NAME .getKey ()) != null ) {
75+ // Backward compatibility for old property
76+ this .appName = clientProperties .get (ClientConfigProperties .PRODUCT_NAME .getKey ()).trim ();
77+ clientName = this .appName + " " + clientName ; // Use the application name as client name
78+ }
79+
6780 if (this .config .isDisableFrameworkDetection ()) {
6881 log .debug ("Framework detection is disabled." );
6982 } else {
7083 String detectedFrameworks = Driver .FrameworksDetection .getFrameworksDetected ();
7184 log .debug ("Detected frameworks: {}" , detectedFrameworks );
72- clientName += " (" + detectedFrameworks + ")" ;
85+ if (!detectedFrameworks .trim ().isEmpty ()) {
86+ clientName += " (" + detectedFrameworks + ")" ;
87+ }
7388 }
7489
7590 this .client = this .config .applyClientProperties (new Client .Builder ())
@@ -441,8 +456,6 @@ public boolean isValid(int timeout) throws SQLException {
441456 return true ;
442457 }
443458
444- private String appName = "" ;
445-
446459 @ Override
447460 public void setClientInfo (String name , String value ) throws SQLClientInfoException {
448461 if (ClientInfoProperties .APPLICATION_NAME .getKey ().equals (name )) {
0 commit comments