You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
statement.execute("SELECT number from numbers(200000) order by number");
57
+
try(ResultSet r = statement.getResultSet()){
58
+
// ** We must call `rs.next()` otherwise the query may be canceled **
59
+
while (rs.next()) {
60
+
System.out.println(r.getInt(1));
61
+
}
62
+
}
60
63
}
61
-
conn.close();
62
64
}
63
65
}
64
66
```
65
67
66
68
### Important Notes
67
69
68
-
1. Because the `select`, `copy into`, `merge into` are query type SQL, they will return a `ResultSet` object, you must
70
+
1. Close Connection/Statement/ResultSet to release resources faster.
71
+
2. Because the `select`, `copy into`, `merge into` are query type SQL, they will return a `ResultSet` object, you must
69
72
call `rs.next()` before accessing the data. Otherwise, the query may be canceled. If you do not want get the result,
70
73
you can call `while(r.next(){})` to iterate over the result set.
71
-
2. For other SQL such as `create/drop table` non-query type SQL, you can call `statement.execute()` directly.
74
+
3. For other SQL such as `create/drop table` non-query type SQL, you can call `statement.execute()` directly.
72
75
73
76
## JDBC Java type mapping
74
77
The Databend type is mapped to Java type as follows:
@@ -99,3 +102,84 @@ For detailed references, please take a look at the following Links:
99
102
100
103
1.[Connection Parameters](./docs/Connection.md) : detailed documentation about how to use connection parameters in a
101
104
jdbc connection
105
+
106
+
107
+
# FileTransfer API
108
+
109
+
The `FileTransferAPI` interface provides a high-performance, Java-based mechanism for streaming data directly between your application and Databend's internal stage, eliminating the need for intermediate local files. It is designed for efficient bulk data operations.
110
+
111
+
## Key Features
112
+
113
+
***Streaming Upload/Download:** Directly transfer data using `InputStream`, supporting large files without excessive memory consumption
114
+
***Direct Table Loading:** Ingest data from streams or staged files directly into Databend tables using the `COPY INTO` command
115
+
***Compression:** Supports on-the-fly compression and decompression during transfer to optimize network traffic
116
+
***Flexible Data Ingestion:** Offers both stage-based and streaming-based methods for loading data into tables
117
+
118
+
## Core Methods
119
+
120
+
### `uploadStream`
121
+
Uploads a data stream as a single file to the specified internal stage.
122
+
123
+
**Parameters:**
124
+
-`stageName`: The stage which will receive the uploaded file
125
+
-`destPrefix`: The prefix of the file name in the stage
126
+
-`inputStream`: The input stream of the file data
127
+
-`destFileName`: The destination file name in the stage
128
+
-`fileSize`: The size of the file being uploaded
129
+
-`compressData`: Whether to compress the data during transfer
130
+
131
+
### `downloadStream`
132
+
Downloads a file from the internal stage and returns it as an `InputStream`.
133
+
134
+
**Parameters:**
135
+
-`stageName`: The stage which contains the file to download
136
+
-`sourceFileName`: The name of the file in the stage
137
+
-`decompress`: Whether to decompress the data during download
138
+
139
+
**Returns:**`InputStream` of the downloaded file content
140
+
141
+
142
+
### `loadStreamToTable`
143
+
A versatile method to load data from a stream directly into a table, using either a staging or streaming approach.
144
+
145
+
Available with databend-jdbc >= 0.4 AND databend-query >= 1.2.791.
146
+
147
+
**Parameters:**
148
+
-`sql`: SQL statement with specific syntax for data loading
149
+
-`inputStream`: The input stream of the file data to load
150
+
-`fileSize`: The size of the file being loaded
151
+
-`loadMethod`: The loading method - "stage" or "streaming". `stage` method first upload file to a special path in user stage, while `steaming` method load data to while transforming data.
152
+
153
+
**Returns:** Number of rows successfully loaded
154
+
155
+
## Quick Start
156
+
157
+
The following example demonstrates how to upload data and load it into a table:
0 commit comments