Skip to content

Commit

Permalink
Use prepared statement in COUNT for execution log
Browse files Browse the repository at this point in the history
  • Loading branch information
alexisszmundy committed Jul 11, 2024
1 parent 647a8ff commit 8c20e94
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
Expand Down Expand Up @@ -97,9 +98,14 @@ public void writeOutputTables(Map<String, MetadataModel> metadataModels) throws

//Count rows for functional log
if (kraftwerkExecutionLog != null) {
try(ResultSet countResult = this.getDatabase().executeQuery("SELECT COUNT(*) FROM " + datasetName)){
countResult.next();
kraftwerkExecutionLog.getLineCountByTableMap().put(datasetName, countResult.getInt(1));
String selectQuery = "SELECT COUNT(*) FROM ?";
try(PreparedStatement preparedStatement = getDatabase().getConnection().prepareStatement(selectQuery)) {
preparedStatement.setString(1, datasetName);
try (ResultSet countResult =
preparedStatement.executeQuery()) {
countResult.next();
kraftwerkExecutionLog.getLineCountByTableMap().put(datasetName, countResult.getInt(1));
}
}
}
} catch (SQLException | IOException e) {
Expand Down

0 comments on commit 8c20e94

Please sign in to comment.