Here you can find the source of resultSetToString(ResultSet resultSet)
public static StringBuilder resultSetToString(ResultSet resultSet) throws SQLException
//package com.java2s; //License from project: Apache License import java.sql.ResultSet; import java.sql.SQLException; import java.sql.ResultSetMetaData; public class Main { public static StringBuilder resultSetToString(ResultSet resultSet) throws SQLException { ResultSetMetaData metaData = resultSet.getMetaData(); int countOfColumns = metaData.getColumnCount(); StringBuilder builder = new StringBuilder(); builder.append("<table>"); builder.append("<tr>"); for (int i = 0; i < countOfColumns; i++) { builder.append("<th>"); builder.append(metaData.getColumnName(i + 1)); builder.append("</th>"); }/*from w ww.j av a 2s .c o m*/ builder.append("</tr>"); while (resultSet.next()) { builder.append("<tr>"); for (int i = 0; i < countOfColumns; i++) { builder.append("<td>"); builder.append(resultSet.getString(i + 1)); builder.append("</td>"); } builder.append("</tr>"); } builder.append("</table>"); return builder; } }