Skip to content

Commit 46b0fd0

Browse files
Merge pull request #183 from data-integrations/PLUGIN-986
PLUGIN-986
2 parents 43757ba + 874c140 commit 46b0fd0

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

database-commons/src/main/java/io/cdap/plugin/db/batch/sink/AbstractDBSink.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,18 +308,20 @@ private void validateSchema(FailureCollector collector, Class<? extends Driver>
308308
return;
309309
}
310310
}
311-
312-
try (PreparedStatement pStmt = connection.prepareStatement("SELECT * FROM " + dbSinkConfig.getEscapedTableName()
313-
+ " WHERE 1 = 0");
311+
setColumnsInfo(inputSchema.getFields());
312+
try (PreparedStatement pStmt = connection.prepareStatement(String.format("SELECT %s FROM %s WHERE 1 = 0",
313+
dbColumns,
314+
dbSinkConfig.getEscapedTableName()));
314315
ResultSet rs = pStmt.executeQuery()) {
315316
getFieldsValidator().validateFields(inputSchema, rs, collector);
316317
}
317318
} catch (SQLException e) {
318319
LOG.error("Exception while trying to validate schema of database table {} for connection {}.",
319320
tableName, connectionString, e);
320321
collector.addFailure(
321-
String.format("Exception while trying to validate schema of database table '%s' for connection '%s'.",
322-
tableName, connectionString), null).withStacktrace(e.getStackTrace());
322+
String.format("Exception while trying to validate schema of database table '%s' for connection '%s' with %s",
323+
tableName, connectionString, e.getMessage()),
324+
null).withStacktrace(e.getStackTrace());
323325
}
324326
}
325327

0 commit comments

Comments
 (0)