@@ -5,158 +5,4 @@ See the [ClickHouse website](https://clickhouse.com/docs/en/integrations/languag
5
5
6
6
## Examples
7
7
For more example please check [ here] ( https://github.com/ClickHouse/clickhouse-java/tree/main/examples/jdbc ) .
8
- ## Upgrade path
9
- ### to 0.3.2+
10
8
11
- Please refer to cheatsheet below to upgrade JDBC driver to 0.3.2+.
12
-
13
- <table >
14
- <thead >
15
- <tr >
16
- <th >#</th >
17
- <th >Item</th >
18
- <th >< ; = 0.3.1-patch</th >
19
- <th >> ; = 0.3.2</th >
20
- </tr >
21
- </thead >
22
- <tbody >
23
- <tr >
24
- <td >1</td >
25
- <td >pom.xml</td >
26
- <td ><pre ><code class =" language-xml " >< ; dependency> ;
27
- <groupId>ru.yandex.clickhouse</groupId>
28
- <artifactId>clickhouse-jdbc</artifactId>
29
- <version>0.3.1-patch</version>
30
- <classifier>shaded</classifier>
31
- <exclusions>
32
- <exclusion>
33
- <groupId>*</groupId>
34
- <artifactId>*</artifactId>
35
- </exclusion>
36
- </exclusions>
37
- < ; /dependency> ;
38
- </code ></pre ></td >
39
- <td ><pre ><code class =" language-xml " >< ; dependency> ;
40
- <groupId>com.clickhouse</groupId>
41
- <artifactId>clickhouse-jdbc</artifactId>
42
- <version>0.3.2-patch11</version>
43
- <classifier>all</classifier>
44
- <exclusions>
45
- <exclusion>
46
- <groupId>*</groupId>
47
- <artifactId>*</artifactId>
48
- </exclusion>
49
- </exclusions>
50
- < ; /dependency> ;
51
- </code ></pre ></td >
52
- </tr >
53
- <tr >
54
- <td >2</td >
55
- <td >driver class</td >
56
- <td >ru.yandex.clickhouse.ClickHouseDriver</td >
57
- <td >com.clickhouse.jdbc.ClickHouseDriver</td >
58
- </tr >
59
- <tr >
60
- <td >3</td >
61
- <td >connection string</td >
62
- <td ><pre ><code class =" language-text " >jdbc:clickhouse://[user[:password]@]host:port[/database][?parameters]</code ></pre ></td >
63
- <td ><pre ><code class =" language-text " >jdbc:(ch|clickhouse)[:protocol]://endpoint[,endpoint][/database][?parameters][#tags]</code ></pre >
64
- <b >endpoint:</b > [ protocol://] host[ : port ] [ /database ] [ ?parameters] [ #tags ] <br />
65
- <b >protocol:</b > (grpc|grpcs|http|https|tcp|tcps)<br />
66
- </td >
67
- </tr >
68
- <tr >
69
- <td >4</td >
70
- <td >custom settings</td >
71
- <td ><pre ><code class =" language-java " >String jdbcUrl = "jdbc:clickhouse://localhost:8123/default?socket_timeout=6000000"
72
- // custom server settings
73
- + "&max_bytes_before_external_group_by=16000000000"
74
- + "&optimize_aggregation_in_order=0"
75
- + "&join_default_strictness=ANY"
76
- + "&join_algorithm=auto"
77
- + "&max_memory_usage=20000000000"; </code></pre></td>
78
- <td ><pre ><code class =" language-java " >String jdbcUrl = "jdbc:clickhouse://localhost/default?socket_timeout=6000000"
79
- // or properties.setProperty("custom_settings", "a=1,b=2,c=3")
80
- + "&custom_settings="
81
- // url encoded settings separated by comma
82
- + "max_bytes_before_external_group_by%3D16000000000%2C"
83
- + "optimize_aggregation_in_order%3D0%2C"
84
- + "join_default_strictness%3DANY%2C"
85
- + "join_algorithm%3Dauto%2C"
86
- + "max_memory_usage%3D20000000000"; </code></pre></td>
87
- </tr >
88
- <tr >
89
- <td >5</td >
90
- <td >load balancing</td >
91
- <td ><pre ><code class =" language-java " >String connString = "jdbc:clickhouse://server1:8123,server2:8123,server3:8123/database";
92
- BalancedClickhouseDataSource balancedDs = new BalancedClickhouseDataSource(
93
- connString).scheduleActualization(5000, TimeUnit.MILLISECONDS);
94
- ClickHouseConnection conn = balancedDs.getConnection("default", "");
95
- </code ></pre ></td >
96
- <td ><pre ><code class =" language-java " >String connString = "jdbc:ch://server1,server2,server3/database"
97
- + "?load_balancing_policy=random&health_check_interval=5000&failover=2";
98
- ClickHouseDataSource ds = new ClickHouseDataSource(connString);
99
- ClickHouseConnection conn = ds.getConnection("default", "");
100
- </code ></pre ></td >
101
- </tr >
102
- <tr >
103
- <td >6</td >
104
- <td >DateTime</td >
105
- <td ><pre ><code class =" language-java " >try (PreparedStatement ps = conn.preparedStatement("insert into mytable(start_datetime, string_value) values(?,?)") {
106
- ps.setObject(1, LocalDateTime.now());
107
- ps.setString(2, "value");
108
- ps.executeUpdate();
109
- }
110
- </code ></pre ></td >
111
- <td ><pre ><code class =" language-java " >try (PreparedStatement ps = conn.preparedStatement("insert into mytable(start_datetime, string_value) values(?,?)") {
112
- // resolution of DateTime32 or DateTime without scale is 1 second
113
- ps.setObject(1, LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS));
114
- ps.setString(2, "value");
115
- ps.executeUpdate();
116
- }
117
- </code ></pre ></td >
118
- </tr >
119
- <tr >
120
- <td >7</td >
121
- <td >extended API</td >
122
- <td ><pre ><code class =" language-java " >ClickHouseStatement sth = connection.createStatement();
123
- sth.write().send("INSERT INTO test.writer", new ClickHouseStreamCallback() {
124
- @Override
125
- public void writeTo(ClickHouseRowBinaryStream stream) throws IOException {
126
- for (int i = 0; i < 10; i++) {
127
- stream.writeInt32(i);
128
- stream.writeString("Name " + i);
129
- }
130
- }
131
- }, ClickHouseFormat.RowBinary); // RowBinary or Native are supported
132
- </code ></pre ></td >
133
- <td ><pre ><code class =" language-java " >// 0.3.2
134
- Statement sth = connection.createStatement();
135
- sth.unwrap(ClickHouseRequest.class).write().table("test.writer")
136
- .format(ClickHouseFormat.RowBinary).data(out -> {
137
- for (int i = 0; i < 10; i++) {
138
- // write data into the piped stream in current thread
139
- BinaryStreamUtils.writeInt32(out, i);
140
- BinaryStreamUtils.writeString(out, "Name " + i);
141
- }
142
- }).sendAndWait();
143
-
144
- // since 0.4
145
- PreparedStatement ps = connection.preparedStatement("insert into test.writer format RowBinary");
146
- ps.setObject(new ClickHouseWriter() {
147
- @Override
148
- public void write(ClickHouseOutputStream out) throws IOException {
149
- for (int i = 0; i < 10; i++) {
150
- // write data into the piped stream in current thread
151
- BinaryStreamUtils.writeInt32(out, i);
152
- BinaryStreamUtils.writeString(out, "Name " + i);
153
- }
154
- }
155
- });
156
- // ClickHouseWriter will be executed in a separate thread
157
- ps.executeUpdate();
158
- </code ></pre ></td >
159
-
160
- </tr >
161
- </tbody >
162
- </table >
0 commit comments