package lt.nsg.jdbcglass.resultset;

import org.slf4j.Logger;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ResultSetLogger {
    public void logResultSetRow(Logger log, ResultSet resultSet) throws SQLException {
        final List<ResultSetColumn> columns = getResultSetColumns(resultSet);
        final String message = createLogMessage(columns);
        log.info(" {}", message);
    }

    private String createLogMessage(List<ResultSetColumn> columns) {
        if (columns.size() == 0) {
            return "{}";
        }
        StringBuilder sb = new StringBuilder();
        sb.append("{");
        for (ResultSetColumn column : columns) {
            sb.append(column.getFormattedStringValue()).append(",");
        }
        sb.replace(sb.length() - 1, sb.length(), "}");
        return sb.toString();
    }

    private List<ResultSetColumn> getResultSetColumns(ResultSet resultSet) throws SQLException {
        final ResultSetMetaData md = resultSet.getMetaData();
        final int columnCount = md.getColumnCount();
        final ArrayList<ResultSetColumn> columns = new ArrayList<>();
        for (int i = 1; i <= columnCount; i++) {
            final String column = resultSet.getObject(i).toString();
            columns.add(new ResultSetColumn(column));
        }
        return columns;
    }
}

@@ -1291,16 +1291,29 @@
 olumn = 
+safeToString(
 resultSe
@@ -1326,26 +1326,16 @@
 bject(i)
-.toString(
 );%0A     
@@ -1385,32 +1385,32 @@
 mn));%0A        %7D%0A
-
         return c
@@ -1422,11 +1422,180 @@
 s;%0A    %7D
+%0A%0A    private static String safeToString(Object o) throws SQLException %7B%0A        if (o == null) %7B%0A            return %22null%22;%0A        %7D%0A        return o.toString();%0A    %7D
 %0A%7D%0A

Check for null before calling toString