clickhouse-java icon indicating copy to clipboard operation
clickhouse-java copied to clipboard

clickhouse-jdbc driver did not support connection url parameters

Open ldcsaa opened this issue 1 year ago • 2 comments

Describe the bug

Clickhouse JDBC connection URL with parameters would be always uses default database, like this:

# the default database is NOT `my_db`, but the `default` db.
url: jdbc:clickhouse://192.168.56.23:8123/my_db?custom_http_params=async_insert=1,wait_for_async_insert=1

If cut the url parameter, that's OK, like this:

# the default database is `my_db`
url: jdbc:clickhouse://192.168.56.23:8123/my_db
  • I had test many version of clickhouse JDBC driver, 0.4.6, 0.5.0, 0.6.0 etc.
  • ClickHouse Server version: 24.1

ldcsaa avatar May 31 '24 11:05 ldcsaa

Good day, @ldcsaa! Thank you for reporting the issue! Am I correct that there are two problems:

  • when query parameters are set then wrong database is selected
  • you would like to pass some parameters thru JDBC url

for the last one - have you tried to url encode this part - async_insert=1,wait_for_async_insert=1 ?

chernser avatar Jun 01 '24 21:06 chernser

Good day, @ldcsaa! Thank you for reporting the issue! Am I correct that there are two problems:

  • when query parameters are set then wrong database is selected
  • you would like to pass some parameters thru JDBC url

for the last one - have you tried to url encode this part - async_insert=1,wait_for_async_insert=1 ?

I did not tried to encode URL, just refer to this guide: Asynchronous Inserts

image

ldcsaa avatar Jun 03 '24 03:06 ldcsaa

Triage Report

  • Bug and should work as documented.

chernser avatar Jul 15 '24 21:07 chernser

There is a version that solves this problem ?

ningObito avatar Jul 25 '24 05:07 ningObito

Good day, @ldcsaa! I've found the bug that causes the problem - , is used as delimiter for endpoints definitions (http://host1,host2,host3/my_db). This will be fixed in 0.7.0. However, custom_settings should be used instead custom_http_params (should not be used because depends on protocol and actually is not working as expected.)

chernser avatar Sep 28 '24 06:09 chernser

@chernser I've updated clickhouse-driver to version 0.8, but passing data like jdbc:clickhouse://127.0.0.1:8123/mysql?custom_settings=log_comment=devel doesn't work anymore. Is this method no longer allowed? Is there any way to achieve the same effect as in version 0.5?

wtao54101 avatar Aug 26 '25 09:08 wtao54101

Good day, @wtao54101 ! Please use clickhouse_settings_log_comment instead to do this configuration. We have aligned Java client with other language clients and all server side settings should have prefix clickhouse_settings_ (see https://clickhouse.com/docs/integrations/language-clients/java/client#server-settings).

Please let me know if it helped or rise an issue.

Thanks!

chernser avatar Aug 26 '25 15:08 chernser