out.println(query);
ResultSetMetaData rsmd = rs.getMetaData();
int count = rsmd.getColumnCount();
int[] sizes = new int[count];
StringWriter types = new StringWriter();
StringWriter columns = new StringWriter();
for (int i = 1; i <= count; i++) {
String columnName = rsmd.getColumnName(i);
String typeName = rsmd.getColumnTypeName(i);
if (maxColWidth == 0) {
// Sets the width of the column to the wider of the column name and the column type name.
sizes[i-1] = Math.max(columnName.length(), typeName.length());
} else {
// Sets the width of the column to the wider of the column name and the column display size (which cannot exceed maxColWidth).
sizes[i-1] = Math.max(Math.max(columnName.length(), typeName.length()), // takes into account the type name width
Math.min(rsmd.getColumnDisplaySize(i), maxColWidth));
}
types.write(resizeString(typeName, sizes[i-1]));
columns.write(resizeString(columnName, sizes[i-1]));
if (i != count) {
types.write(SPACER);
columns.write(SPACER);
}
}
out.println(types.toString());
out.println(columns.toString());
int totalRows = 0;
while (rs.next()) {
for (int j = 1; j <= count; j++) {
if (maxColWidth == 0) {
Object obj = rs.getObject(j);