Java SQL Table Column resultSetToStringFormat(ResultSet rs, String separator, String quote, boolean column)

Here you can find the source of resultSetToStringFormat(ResultSet rs, String separator, String quote, boolean column)

Description

result Set To String Format

License

Apache License

Declaration

public static String resultSetToStringFormat(ResultSet rs, String separator, String quote, boolean column)
            throws SQLException 

Method Source Code


//package com.java2s;
/*/*from w  ww.  ja v  a 2 s . c o  m*/
 * codjo.net
 *
 * Common Apache License 2.0
 */

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

public class Main {
    public static String resultSetToStringFormat(ResultSet rs, String separator, String quote, boolean column)
            throws SQLException {
        StringBuilder sb = new StringBuilder();
        ResultSetMetaData metadata = rs.getMetaData();
        int colmumnCount = metadata.getColumnCount();
        if (column) {
            for (int i = 1; i <= colmumnCount; i++) {
                sb.append(quote).append(metadata.getColumnName(i)).append(quote);
                if (i + 1 <= colmumnCount) {
                    sb.append(separator);
                }
            }
            sb.append("\n");
        }
        while (rs.next()) {
            for (int i = 1; i <= colmumnCount; i++) {
                sb.append(quote).append(rs.getObject(i)).append(quote);
                if (i + 1 <= colmumnCount) {
                    sb.append(separator);
                }
            }
            sb.append("\n");
        }
        return sb.toString();
    }
}

Related

  1. resultSetAsCount(ResultSet rs, String countColumn)
  2. resultSetContainsColumn(ResultSet rs, String column)
  3. resultSetHasColumn(ResultSet rs, String sColumnName)
  4. resultSetToOneColumnAsCommamaSeparatedString(ResultSet rs)
  5. resultSetToOneColumnAsList(ResultSet rs)
  6. resultSetValue(ResultSet resultSet, Class parameterClass, Object object, String columnLabel)
  7. retrieveCoulmns(String tableName, String columnArray[], Statement statement, long offset, long numberOfRecords)
  8. tableContainsColumn(Connection conn, String table, String column)
  9. tableContainsIndex(Connection conn, String table, String column, String index)