使用sqlline通过jdbc连接clickhouse

  |   0 评论   |   1,041 浏览

背景

sqlline支持使用shell来通过jdbc连接关系数据库。

恰好clickhouse符合sqlline的使用场景.

由于支持clickhouse的客户端还不多.

本文尝试使用 sqlline 来连接 clickhouse.

下载

见我的github

打包

mvn clean package

运行

java -cp testSqlline-1.0.0-SNAPSHOT.jar:lib/* sqlline.SqlLine -d ru.yandex.clickhouse.ClickHouseDriver

连接clickhouse

!connect jdbc:clickhouse://ip:8123/database username password

帮助

java -cp testSqlline-1.0.0-SNAPSHOT.jar:lib/* sqlline.SqlLine -d ru.yandex.clickhouse.ClickHouseDriver -h

Usage: java sqlline.SqlLine
   -u <database url>               the JDBC URL to connect to
   -n <username>                   the username to connect as
   -p <password>                   the password to connect as
   -d <driver class>               the driver class to use
   -nn <nickname>                  nickname for the connection
   -f <file>                       script file to execute (same as --run)
   --color=[true/false]            control whether color is used for display
   --showHeader=[true/false]       show column names in query results
   --headerInterval=ROWS           the interval between which headers are displayed
   --fastConnect=[true/false]      skip building table/column list for tab-completion
   --autoCommit=[true/false]       enable/disable automatic transaction commit
   --verbose=[true/false]          show verbose error messages and debug info
   --showTime=[true/false]         display execution time when verbose
   --showWarnings=[true/false]     display connection warnings
   --showNestedErrs=[true/false]   display nested errors
   --numberFormat=[pattern]        format numbers using DecimalFormat pattern
   --force=[true/false]            continue running script even after errors
   --maxWidth=MAXWIDTH             the maximum width of the terminal
   --maxColumnWidth=MAXCOLWIDTH    the maximum width to use when displaying columns
   --silent=[true/false]           be more silent
   --autosave=[true/false]         automatically save preferences
   --outputformat=[table/vertical/csv/tsv]   format mode for result display
   --isolation=LEVEL               set the transaction isolation level
   --run=/path/to/file             run one script and then exit

直接连接

java -cp testSqlline-1.0.0-SNAPSHOT.jar:lib/* sqlline.SqlLine -d ru.yandex.clickhouse.ClickHouseDriver -u jdbc:clickhouse://ip:8123/database -n username -p password -nn ch

缺点

  • 不支持进度条, clickhouse-client支持进度条.

参考

评论

发表评论

validate