use of com.github.noraui.exception.data.DatabaseException in project NoraUi by NoraUi.
the class DBDataProvider method initColumns.
private void initColumns() throws DatabaseException, TechnicalException {
columns = new ArrayList<>();
String sqlRequest;
try {
final Path file = Paths.get(dataInPath + scenarioName + ".sql");
sqlRequest = new String(Files.readAllBytes(file), Charset.forName(Constants.DEFAULT_ENDODING));
sqlSanitized4readOnly(sqlRequest);
} catch (final IOException e) {
throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE) + e.getMessage(), e);
}
try (Connection connection = getConnection();
PreparedStatement statement = connection.prepareStatement(sqlRequest);
ResultSet rs = statement.executeQuery()) {
if (rs.getMetaData().getColumnCount() < 1) {
throw new DatabaseException("Input data is empty. No column have been found.");
}
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
columns.add(rs.getMetaData().getColumnLabel(i));
}
} catch (final SQLException e) {
throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE) + e.getMessage(), e);
}
resultColumnName = Messages.getMessage(ResultColumnNames.RESULT_COLUMN_NAME);
}
Aggregations