@Override public String extractData(ResultSet resultSet) throws SQLException, DataAccessException { RowCountCallbackHandler rowCountCallbackHandler = new RowCountCallbackHandler(); rowCountCallbackHandler.processRow(resultSet); int columnCount = resultSet.getMetaData().getColumnCount(); List<String> columnNames = asList(rowCountCallbackHandler.getColumnNames()); String header = getHeader(columnNames); StringBuilder result = new StringBuilder(header); result.append("\n"); while (resultSet.next()) { StringBuilder stringBuilder = new StringBuilder(); int i = 1; while (i <= columnCount) { stringBuilder.append(resultSet.getObject(i)); if (i < columnCount) { stringBuilder.append(" | "); } i++; } result.append(stringBuilder.toString()).append("\n"); } return result.toString(); }
public int count(String countQuery) { RowCountCallbackHandler rowCountCallbackHandler = new RowCountCallbackHandler(); jdbcTemplate.query(countQuery, rowCountCallbackHandler); return rowCountCallbackHandler.getRowCount(); }
public int countRows(String sql, Object... values) { RowCountCallbackHandler counter = new RowCountCallbackHandler(); getJdbcTemplate().getJdbcOperations().query(sql, values, counter); return counter.getRowCount(); }