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
{{ message }}
This repository was archived by the owner on Dec 30, 2020. It is now read-only.
pstatement.setObject(3, new ByteArrayInputStream("test".getBytes("UTF-8"))); // blob
175
175
pstatement.setObject(4, true); // boolean
176
176
pstatement.setObject(5, new BigDecimal(5.1)); // decimal
@@ -184,7 +184,7 @@ Prepared statements to insert a record in "table1"::
184
184
UUID uuid = UUID.randomUUID();
185
185
pstatement.setObject(12, uuid ); // uuid
186
186
pstatement.setObject(13, "test"); // varchar
187
-
pstatement.setObject(14, 1);
187
+
pstatement.setObject(14, 1);
188
188
HashSet<String> mySet = new HashSet<String>();
189
189
mySet.add("test");
190
190
mySet.add("test");
@@ -197,7 +197,7 @@ Prepared statements to insert a record in "table1"::
197
197
myMap.put("1","test");
198
198
myMap.put("2","test");
199
199
pstatement.setObject(17, myMap);
200
-
200
+
201
201
pstatement.execute();
202
202
203
203
@@ -215,20 +215,20 @@ With simple statements::
215
215
for(int i=0;i<10;i++){
216
216
statement.addBatch("INSERT INTO testcollection (k,L) VALUES( " + i + ",[1, 3, 12345])");
217
217
}
218
-
218
+
219
219
int[] counts = statement.executeBatch();
220
220
statement.close();
221
221
222
222
With prepared statements::
223
223
224
224
PreparedStatement statement = con.prepareStatement("INSERT INTO testcollection (k,L) VALUES(?,?)");
225
-
225
+
226
226
for(int i=0;i<10;i++){
227
227
statement.setInt(1, i);
228
228
statement.setString(2, "[1, 3, 12345]");
229
229
statement.addBatch();
230
230
}
231
-
231
+
232
232
int[] counts = statement.executeBatch();
233
233
statement.close();
234
234
@@ -237,12 +237,12 @@ With prepared statements::
237
237
The second one is to put all the queries in a single CQL statement, each ended with a semicolon (;)::
238
238
239
239
Statement statement = con.createStatement();
240
-
241
-
StringBuilder queryBuilder = new StringBuilder();
240
+
241
+
StringBuilder queryBuilder = new StringBuilder();
242
242
for(int i=0;i<10;i++){
243
243
queryBuilder.append("INSERT INTO testcollection (k,L) VALUES( " + i + ",[1, 3, 12345]);");
244
244
}
245
-
245
+
246
246
statement.execute(queryBuilder.toString());
247
247
statement.close();
248
248
@@ -255,15 +255,15 @@ As JDBC batches do not support returning result sets, there is only one way to s
255
255
for(int i=0;i<10;i++){
256
256
queries.append("SELECT * FROM testcollection where k = "+ i + ";");
257
257
}
258
-
258
+
259
259
//send all select queries at onces
260
260
ResultSet result = statement.executeQuery(queries.toString());
261
261
262
262
int nbRow = 0;
263
-
ArrayList<Integer> ids = new ArrayList<Integer>();
263
+
ArrayList<Integer> ids = new ArrayList<Integer>();
264
264
265
265
// get all results from all the select queries in a single result set
266
-
while(result.next()){
266
+
while(result.next()){
267
267
ids.add(result.getInt("k"));
268
268
}
269
269
@@ -274,32 +274,32 @@ Working with Tuples and UDTs
274
274
----------------------------
275
275
276
276
To create a new Tuple object in Java, use the TupleType.of().newValue() method.
277
-
UDT fields cannot be instantiated outside of the Datastax Java driver core. If you want to use prepared statements, you must proceed as in the following example::
277
+
UDT fields cannot be instantiated outside of the Datastax Java driver core. If you want to use prepared statements, you must proceed as in the following example::
278
278
279
279
String createUDT = "CREATE TYPE IF NOT EXISTS fieldmap (key text, value text )";
0 commit comments