Skip to content

Instantly share code, notes, and snippets.

@AARomanov1985
Created January 29, 2016 12:27
Show Gist options
  • Save AARomanov1985/33c004a8bed663379035 to your computer and use it in GitHub Desktop.
Save AARomanov1985/33c004a8bed663379035 to your computer and use it in GitHub Desktop.
Универсальный метод обработки SQL-запросов
public List<Record> getResult(String query) {
List<Record> out = new ArrayList<>();
try (Statement statement = connection.createStatement()) {
logConnect(query);
ResultSet result = statement.executeQuery(query);
while (result.next()) {
Record record = new Record();
try {
for (int i = 1;; i++) {
record.addValue(result.getString(i));
}
} catch (SQLException sqlex) {
log.log(this.getClass().getName() + ": метод getResult(String query): " + sqlex.fillInStackTrace(), Log.Detail.NORMAL);
}
out.add(record);
}
} catch (SQLException ex) {
log.log(this.getClass().getName() + ": исключение в методе getFidList: " + ex.fillInStackTrace(), Log.Detail.ERROR);
}
return out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment