Skip to content

Commit

Permalink
update SqlServerImportJob to use "drop table" command compatible with…
Browse files Browse the repository at this point in the history
… earlier versions of SQL Server
  • Loading branch information
mogoodrich committed Jul 16, 2020
1 parent 250f3f2 commit e5164e2
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/main/java/org/pih/petl/job/type/SqlServerImportJob.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package org.pih.petl.job.type;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Iterator;
import java.util.List;

import com.microsoft.sqlserver.jdbc.ISQLServerConnection;
import com.microsoft.sqlserver.jdbc.SQLServerBulkCopy;
import com.microsoft.sqlserver.jdbc.SQLServerBulkCopyOptions;
Expand All @@ -25,6 +18,13 @@
import org.pih.petl.job.datasource.EtlDataSource;
import org.pih.petl.job.datasource.SqlStatementParser;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Iterator;
import java.util.List;

/**
* PetlJob that can load into SQL Server table
*/
Expand Down Expand Up @@ -89,9 +89,9 @@ public void execute(final ExecutionContext context) throws Exception {
sourceConnection.setAutoCommit(false); // We intend to rollback changes to source after querying DB
targetConnection.setAutoCommit(true); // We want to commit to target as we go, to query status

// First, drop any existing target table
// First, drop any existing target table (we don't use "drop table if exists..." syntax for backwards compatibility with earlier versions of SQL Server
context.setStatus("Dropping existing table");
qr.update(targetConnection, "drop table if exists " + targetTable);
qr.update(targetConnection, "IF OBJECT_ID('dbo." + targetTable+ "') IS NOT NULL DROP TABLE dbo." + targetTable);

// Then, recreate the target table
context.setStatus("Creating table");
Expand Down

0 comments on commit e5164e2

Please sign in to comment.