-
Notifications
You must be signed in to change notification settings - Fork 456
Update JDBC docs for V2 #3071
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Update JDBC docs for V2 #3071
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
23f72bf
Update jdbc-driver.md
45de647
Updating docs to save the older version
4722698
Update sidebars.js
a84f4e7
Updating misc usage of the old url
c9fcffb
Update jdbc-v2.md
4a34335
Update jdbc-v2.md
cadd941
Merge branch 'main' into update-jdbc-docs
dabef88
Update docs/en/integrations/language-clients/java/jdbc-v2.md
Paultagoras f07e7a0
Docs cleanup
0509982
Update jdbc-v2.md
da1324e
Update jdbc-v2.md
45d2389
Style changes
33952fe
Style
060735d
Update jdbc-v1.md
4bd4af5
Navigation change
5f33e67
Update jdbc-v2.md
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| --- | ||
| sidebar_label: JDBC V2 | ||
| sidebar_position: 4 | ||
| keywords: [clickhouse, java, jdbc, driver, integrate] | ||
| description: ClickHouse JDBC driver V2 | ||
| slug: /en/integrations/java/jdbc-v2 | ||
| --- | ||
|
|
||
| import Tabs from '@theme/Tabs'; | ||
| import TabItem from '@theme/TabItem'; | ||
| import CodeBlock from '@theme/CodeBlock'; | ||
|
|
||
|
|
||
| # JDBC Driver | ||
|
|
||
| `clickhouse-jdbc` implements the standard JDBC interface. Being built on top of [clickhouse-client](/docs/en/integrations/sql-clients/sql-console), it provides additional features like custom type mapping, transaction support, and standard synchronous `UPDATE` and `DELETE` statements, etc., so that it can be easily used with legacy applications and tools. | ||
Paultagoras marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| :::note | ||
| Latest JDBC (0.8.0) version uses Client-V2 by default. | ||
Paultagoras marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ::: | ||
|
|
||
| `clickhouse-jdbc` API is synchronous, and generally, it has more overheads (e.g., SQL parsing and type mapping/conversion, etc.). Consider [client-v2](/docs/en/integrations/language-clients/java/client-v2.md) when performance is critical or if you prefer a more direct way to access ClickHouse. | ||
|
|
||
| ## Environment requirements | ||
|
|
||
| - [OpenJDK](https://openjdk.java.net) version >= 8 | ||
|
|
||
|
|
||
| ### Setup | ||
|
|
||
| <Tabs groupId="jdbc-base-dependencies"> | ||
| <TabItem value="maven" label="Maven" > | ||
|
|
||
| ```xml | ||
| <!-- https://mvnrepository.com/artifact/com.clickhouse/clickhouse-jdbc --> | ||
| <dependency> | ||
| <groupId>com.clickhouse</groupId> | ||
| <artifactId>clickhouse-jdbc</artifactId> | ||
| <version>0.8.0</version> | ||
| <!-- use uber jar with all dependencies included, change classifier to http for smaller jar --> | ||
| <classifier>shaded-all</classifier> | ||
| </dependency> | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="gradle-kt" label="Gradle (Kotlin)"> | ||
|
|
||
| ```kotlin | ||
| // https://mvnrepository.com/artifact/com.clickhouse/clickhouse-jdbc | ||
| // use uber jar with all dependencies included, change classifier to http for smaller jar | ||
| implementation("com.clickhouse:clickhouse-jdbc:0.8.0:shaded-all") | ||
| ``` | ||
| </TabItem> | ||
| <TabItem value="gradle" label="Gradle"> | ||
|
|
||
| ```groovy | ||
| // https://mvnrepository.com/artifact/com.clickhouse/clickhouse-jdbc | ||
| // use uber jar with all dependencies included, change classifier to http for smaller jar | ||
| implementation 'com.clickhouse:clickhouse-jdbc:0.8.0:shaded-all' | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| Since version `0.5.0`, we are using Apache HTTP Client that's packed the Client. Since there is not a shared version of the package, you need to add a logger as a dependency. | ||
Paultagoras marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <Tabs groupId="jdbc-logging-dependency"> | ||
| <TabItem value="maven" label="Maven" > | ||
|
|
||
| ```xml | ||
| <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api --> | ||
| <dependency> | ||
| <groupId>org.slf4j</groupId> | ||
| <artifactId>slf4j-api</artifactId> | ||
| <version>2.0.16</version> | ||
| </dependency> | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="gradle-kt" label="Gradle (Kotlin)"> | ||
|
|
||
| ```kotlin | ||
| // https://mvnrepository.com/artifact/org.slf4j/slf4j-api | ||
| implementation("org.slf4j:slf4j-api:2.0.16") | ||
| ``` | ||
| </TabItem> | ||
| <TabItem value="gradle" label="Gradle"> | ||
|
|
||
| ```groovy | ||
| // https://mvnrepository.com/artifact/org.slf4j/slf4j-api | ||
| implementation 'org.slf4j:slf4j-api:2.0.16' | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| ## Configuration | ||
|
|
||
| **Driver Class**: `com.clickhouse.jdbc.ClickHouseDriver` | ||
|
|
||
| **URL Syntax**: `jdbc:(ch|clickhouse)[:<protocol>]://endpoint1[,endpoint2,...][/<database>][?param1=value1¶m2=value2][#tag1,tag2,...]`, for example: | ||
|
|
||
| - `jdbc:clickhouse:http://localhost:8123` | ||
| - `jdbc:clickhouse:https://localhost:8443?ssl=true&sslmode=STRICT` | ||
Paultagoras marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| **Connection Properties**: | ||
|
|
||
| Beyond standard JDBC properties, the driver supports the ClickHouse-specific properties offered by the underlying [client](/docs/en/integrations/language-clients/java/client-v2.md). | ||
| Where possible methods will return an SQLFeatureNotSupportedException if the feature is not supported. Other custom properties include: | ||
Paultagoras marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| | Property | Default | Description | | ||
| |----------------------------------|---------|---------------------------------------------| | ||
| | `disable_frameworks_detection` | `true` | Disable frameworks detection for User-Agent | | ||
| | `jdbc_ignore_unsupported_values` | `false` | Suppresses SQLFeatureNotSupportedException | | ||
| | `clickhouse.jdbc.v1` | `false` | Use JDBC-V1 instead of JDBC-V2 | | ||
Paultagoras marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Supported data types | ||
|
|
||
| JDBC Driver supports same data formats as the client library does. | ||
Paultagoras marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| :::note | ||
| - AggregatedFunction - :warning: does not support `SELECT * FROM table ...` | ||
| - Decimal - `SET output_format_decimal_trailing_zeros=1` in 21.9+ for consistency | ||
| - Enum - can be treated as both string and integer | ||
| - UInt64 - mapped to `long` (in client-v1) | ||
Paultagoras marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ::: | ||
|
|
||
| ## Creating Connection | ||
|
|
||
| ```java | ||
| String url = "jdbc:ch://my-server:8123/system"; // use http protocol | ||
Paultagoras marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Properties properties = new Properties(); | ||
|
|
||
| DataSource dataSource = new DataSource(url, properties); | ||
| try (Connection conn = dataSource.getConnection("default", "password"); | ||
| Statement stmt = conn.createStatement()) { | ||
| } | ||
| ``` | ||
|
|
||
| ## Simple Statement | ||
|
|
||
| ```java showLineNumbers | ||
|
|
||
| try (Connection conn = dataSource.getConnection(...); | ||
| Statement stmt = conn.createStatement()) { | ||
| ResultSet rs = stmt.executeQuery("select * from numbers(50000)"); | ||
| while(rs.next()) { | ||
| // ... | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Insert | ||
Paultagoras marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ```java showLineNumbers | ||
| try (PreparedStatement ps = conn.prepareStatement("INSERT INTO mytable VALUES (?, ?)")) { | ||
| ps.setString(1, "test"); // id | ||
| ps.setObject(2, LocalDateTime.now()); // timestamp | ||
| ps.addBatch(); | ||
| ... | ||
| ps.executeBatch(); // stream everything on-hand into ClickHouse | ||
| } | ||
| ``` | ||
|
|
||
| ## More Information | ||
Paultagoras marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| For more information, see our [GitHub repository](https://github.com/ClickHouse/clickhouse-java) and [Client-V2 documentation](/docs/en/integrations/language-clients/java/client-v2.md). | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@laeg What about using the client versioning? There will be 2 pages:
We can manually add more pages if necessary and they always transparently mapped to JDBC release version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i would prefer if we aligned it more to release versions rather than internal code versions.
did we look into whether we could do something more elegant for versioning the docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't manage to find a solution in 30min.