Example usage for org.springframework.jdbc.core RowCountCallbackHandler getColumnNames

List of usage examples for org.springframework.jdbc.core RowCountCallbackHandler getColumnNames

Introduction

In this page you can find the example usage for org.springframework.jdbc.core RowCountCallbackHandler getColumnNames.

Prototype

@Nullable
public final String[] getColumnNames() 

Source Link

Document

Return the names of the columns.

Usage

From source file:io.github.benas.jql.shell.StringResultSetExtractor.java

@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(" | ");
            }/*from   www  .j ava 2  s  . c  o  m*/
            i++;
        }
        result.append(stringBuilder.toString()).append("\n");
    }

    return result.toString();
}