public StringBuilder displayResult(final ResultSet rs) {
		try {
			List<String> keys = new ArrayList<>();
			Map<String, Integer> maxLengthList = new HashMap<>();
			ResultSetMetaData rsmd = rs.getMetaData();
			int columnCount = rsmd.getColumnCount();
			for (int i = 1; i <= columnCount; i++) {
				String columnLabel = rsmd.getColumnLabel(i);
				keys.add(columnLabel);
				maxLengthList.put(columnLabel, getByteLength(columnLabel));
			}

			List<Map<String, Object>> rows = new ArrayList<>();

			while (rs.next()) {
				Map<String, Object> data = new HashMap<>();

				for (String key : keys) {
					Object val = rs.getObject(key);
					data.put(key, val);

					int currentLength = getByteLength(val);
					maxLengthList.compute(key, (k, v) -> v < currentLength ? currentLength : v);
				}
				rows.add(data);
			}

			StringBuilder builder = new StringBuilder(System.lineSeparator());
			// ヘッダ部出力
			builder.append("+");
			for (String key : keys) {
				builder.append(FRAME_STR.substring(0, maxLengthList.get(key))).append("+");
			}
			builder.append(System.lineSeparator()).append("|");
			for (String key : keys) {
				builder.append(fillHeader(key, maxLengthList.get(key))).append("|");
			}
			builder.append(System.lineSeparator()).append("+");
			for (String key : keys) {
				builder.append(FRAME_STR.substring(0, maxLengthList.get(key))).append("+");
			}

			// データ部出力

			if (rows.isEmpty()) {
				builder.append(System.lineSeparator()).append("|");
				int len = 1;
				for (String key : keys) {
					len = len + maxLengthList.get(key) + 1;
				}

				if (len >= 13) {
					builder.append("empty data.").append(SPACE_STR.substring(0, len - 13)).append("|");
				} else {
					builder.append("-").append(SPACE_STR.substring(0, len - 2)).append("|");
				}
			} else {
				for (Map<String, Object> row : rows) {
					builder.append(System.lineSeparator()).append("|");
					for (String key : keys) {
						builder.append(fillData(row.get(key), maxLengthList.get(key))).append("|");
					}
				}

			}
			builder.append(System.lineSeparator()).append("+");
			for (String key : keys) {
				builder.append(FRAME_STR.substring(0, maxLengthList.get(key))).append("+");
			}

			// カーソルを先頭の前に戻す
			if (rs.getType() != ResultSet.TYPE_FORWARD_ONLY) {
				rs.beforeFirst();
			}

			return builder;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
public StringBuilder displayResult ( final ResultSet rs ) { try { List < String > keys = new ArrayList < > ( ) ; Map < String , Integer > maxLengthList = new HashMap < > ( ) ; ResultSetMetaData rsmd = rs . getMetaData ( ) ; int columnCount = rsmd . getColumnCount ( ) ; for ( int i = 1 ; i <= columnCount ; i ++ ) { String columnLabel = rsmd . getColumnLabel ( i ) ; keys . add ( columnLabel ) ; maxLengthList . put ( columnLabel , getByteLength ( columnLabel ) ) ; } List < Map < String , Object > > rows = new ArrayList < > ( ) ; while ( rs . next ( ) ) { Map < String , Object > data = new HashMap < > ( ) ; for ( String key : keys ) { Object val = rs . getObject ( key ) ; data . put ( key , val ) ; int currentLength = getByteLength ( val ) ; maxLengthList . compute ( key , ( k , v ) -> v < currentLength ? currentLength : v ) ; } rows . add ( data ) ; } StringBuilder builder = new StringBuilder ( System . lineSeparator ( ) ) ; builder . append ( "+" ) ; for ( String key : keys ) { builder . append ( FRAME_STR . substring ( 0 , maxLengthList . get ( key ) ) ) . append ( "+" ) ; } builder . append ( System . lineSeparator ( ) ) . append ( "|" ) ; for ( String key : keys ) { builder . append ( fillHeader ( key , maxLengthList . get ( key ) ) ) . append ( "|" ) ; } builder . append ( System . lineSeparator ( ) ) . append ( "+" ) ; for ( String key : keys ) { builder . append ( FRAME_STR . substring ( 0 , maxLengthList . get ( key ) ) ) . append ( "+" ) ; } if ( rows . isEmpty ( ) ) { builder . append ( System . lineSeparator ( ) ) . append ( "|" ) ; int len = 1 ; for ( String key : keys ) { len = len + maxLengthList . get ( key ) + 1 ; } if ( len >= 13 ) { builder . append ( "empty data." ) . append ( SPACE_STR . substring ( 0 , len - 13 ) ) . append ( "|" ) ; } else { builder . append ( "-" ) . append ( SPACE_STR . substring ( 0 , len - 2 ) ) . append ( "|" ) ; } } else { for ( Map < String , Object > row : rows ) { builder . append ( System . lineSeparator ( ) ) . append ( "|" ) ; for ( String key : keys ) { builder . append ( fillData ( row . get ( key ) , maxLengthList . get ( key ) ) ) . append ( "|" ) ; } } } builder . append ( System . lineSeparator ( ) ) . append ( "+" ) ; for ( String key : keys ) { builder . append ( FRAME_STR . substring ( 0 , maxLengthList . get ( key ) ) ) . append ( "+" ) ; } if ( rs . getType ( ) != ResultSet . TYPE_FORWARD_ONLY ) { rs . beforeFirst ( ) ; } return builder ; } catch ( Exception e ) { e . printStackTrace ( ) ; } return null ; }
検索結果を表示

@param rs 検索結果のResultSet
@return 表示文字列