|
3 | 3 |  |
4 | 4 | [](https://central.sonatype.dev/artifact/com.databend/databend-jdbc/0.0.1) |
5 | 5 |
|
| 6 | +## Highlights |
| 7 | + |
| 8 | +- Databend-specific interfaces to stream files into tables or stages with `loadStreamToTable`, `uploadStream`, and `downloadStream`. |
| 9 | +- Temporal APIs use session timezone to avoid depending on JVM default zone and support modern `java.time`. |
| 10 | + |
6 | 11 | ## Prerequisites |
7 | 12 |
|
8 | 13 | The Databend JDBC driver requires Java 8 or later. |
@@ -73,36 +78,60 @@ public class Main { |
73 | 78 | you can call `while(r.next(){})` to iterate over the result set. |
74 | 79 | 3. For other SQL such as `create/drop table` non-query type SQL, you can call `statement.execute()` directly. |
75 | 80 |
|
76 | | -## JDBC Java type mapping |
77 | | -The Databend type is mapped to Java type as follows: |
78 | 81 |
|
79 | | -| Databend Type | Java Type | |
80 | | -|---------------|------------| |
81 | | -| TINYINT | Byte | |
82 | | -| SMALLINT | Short | |
83 | | -| INT | Integer | |
84 | | -| BIGINT | Long | |
85 | | -| UInt8 | Short | |
86 | | -| UInt16 | Integer | |
87 | | -| UInt32 | Long | |
88 | | -| UInt64 | BigInteger | |
89 | | -| Float32 | Float | |
90 | | -| Float64 | Double | |
91 | | -| String | String | |
92 | | -| Date | String | |
93 | | -| TIMESTAMP | String | |
94 | | -| Bitmap | byte[] | |
95 | | -| Array | String | |
96 | | -| Decimal | BigDecimal | |
97 | | -| Tuple | String | |
98 | | -| Map | String | |
99 | | -| VARIANT | String | |
| 82 | +## Connection Parameters |
100 | 83 |
|
101 | 84 | For detailed references, please take a look at the following Links: |
102 | 85 |
|
103 | 86 | 1. [Connection Parameters](./docs/Connection.md) : detailed documentation about how to use connection parameters in a |
104 | 87 | jdbc connection |
105 | 88 |
|
| 89 | +## JDBC Java type mapping |
| 90 | +The Databend type is mapped to Java type as follows: |
| 91 | + |
| 92 | +| Databend Type | Java Type | |
| 93 | +|---------------|----------------| |
| 94 | +| TINYINT | Byte | |
| 95 | +| SMALLINT | Short | |
| 96 | +| INT | Integer | |
| 97 | +| BIGINT | Long | |
| 98 | +| UInt8 | Short | |
| 99 | +| UInt16 | Integer | |
| 100 | +| UInt32 | Long | |
| 101 | +| UInt64 | BigInteger | |
| 102 | +| Float32 | Float | |
| 103 | +| Float64 | Double | |
| 104 | +| Decimal | BigDecimal | |
| 105 | +| String | String | |
| 106 | +| Date | LocalDate | |
| 107 | +| TIMESTAMP | ZonedDateTime | |
| 108 | +| TIMESTAMP_TZ | OffsetDateTime | |
| 109 | +| Bitmap | byte[] | |
| 110 | +| Array | String | |
| 111 | +| Tuple | String | |
| 112 | +| Map | String | |
| 113 | +| VARIANT | String | |
| 114 | + |
| 115 | +### Temporal types |
| 116 | + |
| 117 | +we recommend using `java.time` to avoid ambiguity and letting the driver format values via these APIs: |
| 118 | + |
| 119 | +``` |
| 120 | +void setObject(int parameterIndex, Object x) |
| 121 | +<T> T getObject(int columnIndex, Class<T> type) |
| 122 | +``` |
| 123 | + |
| 124 | +- TIMESTAMP_TZ and TIMESTAMP map to `OffsetDateTime`, `ZonedDateTime`, `Instant` (TIMESTAMP_TZ can return `OffsetDateTime` but not `ZonedDateTime`), and `LocalDateTime`. |
| 125 | +- Date maps to `LocalDate`, and `getObject(..., LocalDate.class)` now mirrors what `getDate().toLocalDate()` returns. |
| 126 | +- When a TIMESTAMP literal omits a timezone, Databend uses the session timezone (not the JVM zone) when storing/returning dates on versions ≥0.4.3 driver + ≥1.2.844 server. |
| 127 | + |
| 128 | +Timestamp/Date are also supported, note that: |
| 129 | + |
| 130 | +- `getTimestamp(int, Calendar cal)` is the same as `getTimestamp(int)` (the cal is omitted) and |
| 131 | +`getObject(int, Instant.classes).toTimestamp()` |
| 132 | +- `setTimestamp(int, Calendar cal)` is diff with `setTimestamp(int)`, the epoch is adjusted according to timezone in cal |
| 133 | +- `setDate`/`getDate` still use the JVM timezone, and `setObject(localDate)` is equivalent to `setDate(Date.valueOf(localDate))`. |
| 134 | + |
106 | 135 |
|
107 | 136 | # Unwrapping to Databend-specific interfaces |
108 | 137 |
|
@@ -171,4 +200,3 @@ Download a single file in the stage as `InputStream` |
171 | 200 | ``` |
172 | 201 | InputStream downloadStream(String stageName, String filePathInStage) throws SQLException; |
173 | 202 | ``` |
174 | | - |
|
0 commit comments