@@ -320,108 +320,6 @@ public void testBulkInsertNoOptions() throws Exception {
320
320
}
321
321
}
322
322
323
- /**
324
- * Test with useBulkCopyBatchInsert=true passing SQLServerBulkCopyOptions with
325
- * constraint check enabled
326
- *
327
- * @throws SQLException
328
- */
329
- @ Test
330
- public void testBulkInsertWithConstraintCheckEnabled () throws Exception {
331
- // Set BulkCopy options
332
- SQLServerBulkCopyOptions options = new SQLServerBulkCopyOptions ();
333
- // options.setKeepIdentity(true); // Preserve identity values from the source
334
- options .setCheckConstraints (true ); // enable constraint checks
335
- // options.setTableLock(true); // Lock the destination table for faster insert
336
- // options.setBatchSize(1000); // Batch size for the bulk copy
337
- // options.setTimeout(60); // Timeout in seconds
338
-
339
- try (Connection connection = PrepUtil .getConnection (connectionString + ";useBulkCopyForBatchInsert=true;" )) {
340
- try (PreparedStatement pstmt = connection .prepareStatement ("insert into " + tableName + " values(?, ?)" )) {
341
-
342
- ((SQLServerPreparedStatement ) pstmt ).setBulkCopyOptions (options );
343
-
344
- pstmt .setInt (1 , 1 );
345
- pstmt .setInt (2 , 0 );
346
- pstmt .addBatch ();
347
-
348
- pstmt .setInt (1 , 2 );
349
- pstmt .setInt (2 , 2 );
350
- pstmt .addBatch ();
351
-
352
- pstmt .setInt (1 , 3 );
353
- pstmt .setInt (2 , 0 );
354
- pstmt .addBatch ();
355
-
356
- pstmt .setInt (1 , 4 );
357
- pstmt .setInt (2 , 4 );
358
- pstmt .addBatch ();
359
-
360
- pstmt .executeBatch ();
361
-
362
- fail (TestResource .getResource ("R_expectedExceptionNotThrown" ));
363
-
364
- }
365
- } catch (SQLException e ) {
366
- if (!e .getMessage ().contains ("CHECK" )) {
367
- fail (TestResource .getResource ("R_unexpectedException" ) + e .getMessage ());
368
- }
369
- }
370
- }
371
-
372
- /**
373
- * Test with useBulkCopyBatchInsert=true passing SQLServerBulkCopyOptions with
374
- * constraint check disabled
375
- *
376
- * @throws SQLException
377
- */
378
- @ Test
379
- public void testBulkInsertWithConstraintCheckDisabled () throws Exception {
380
- // Set BulkCopy options
381
- SQLServerBulkCopyOptions options = new SQLServerBulkCopyOptions ();
382
- // options.setKeepIdentity(true); // Preserve identity values from the source
383
- options .setCheckConstraints (false ); // enable constraint checks
384
- // options.setTableLock(true); // Lock the destination table for faster insert
385
- // options.setBatchSize(1000); // Batch size for the bulk copy
386
- // options.setTimeout(60); // Timeout in seconds
387
-
388
- try (Connection connection = PrepUtil .getConnection (connectionString + ";useBulkCopyForBatchInsert=true;" )) {
389
- try (PreparedStatement pstmt = connection .prepareStatement ("insert into " + tableName + " values(?, ?)" )) {
390
-
391
- ((SQLServerPreparedStatement ) pstmt ).setBulkCopyOptions (options );
392
-
393
- pstmt .setInt (1 , 1 );
394
- pstmt .setInt (2 , 0 );
395
- pstmt .addBatch ();
396
-
397
- pstmt .setInt (1 , 2 );
398
- pstmt .setInt (2 , 2 );
399
- pstmt .addBatch ();
400
-
401
- pstmt .setInt (1 , 3 );
402
- pstmt .setInt (2 , 0 );
403
- pstmt .addBatch ();
404
-
405
- pstmt .setInt (1 , 4 );
406
- pstmt .setInt (2 , 4 );
407
- pstmt .addBatch ();
408
-
409
- pstmt .executeBatch ();
410
-
411
- try (Statement stmt = connection .createStatement ()) {
412
- try (ResultSet rs = stmt .executeQuery ("select count(*) from " + tableName )) {
413
- if (rs .next ()) {
414
- int cnt = rs .getInt (1 );
415
- assertEquals (cnt , 4 , "row count should have been 4" );
416
- }
417
- }
418
- }
419
- }
420
- } catch (SQLException e ) {
421
- fail (TestResource .getResource ("R_unexpectedException" ) + e .getMessage ());
422
- }
423
- }
424
-
425
323
/**
426
324
* Test with useBulkCopyBatchInsert=true and
427
325
* bulkCopyOptionDefaultsTableLock=true
0 commit comments