Java SQL ResultSet Read getResultSetRowString(ResultSet rs)

Here you can find the source of getResultSetRowString(ResultSet rs)

Description

Turn all columns into one ; delimited seting Primarily useful in testing that two rows are equivalent

License

Apache License

Parameter

Parameter Description
rs non-null result set positioned at a valid row

Exception

Parameter Description
SQLException an exception

Return

non-null string concatinating all column data

Declaration

public static String getResultSetRowString(ResultSet rs) throws SQLException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.sql.*;

public class Main {
    /**/* w  w  w  .j ava  2  s. co  m*/
     * Turn all columns into one ; delimited seting Primarily useful in
     * testing that two rows are equivalent
     *
     * @param rs non-null result set positioned at a valid row
     * @return non-null string concatinating all column data
     * @throws SQLException
     */
    public static String getResultSetRowString(ResultSet rs) throws SQLException {
        int nCols = getNumberColumns(rs);
        StringBuffer sb = new StringBuffer();

        for (int i = 0; i < nCols; i++) {
            sb.append(rs.getString(i + 1));
            if (i < nCols - 1)
                sb.append(";");
        }
        return (sb.toString());
    }

    public static int getNumberColumns(ResultSet rs) throws SQLException {
        ResultSetMetaData md = rs.getMetaData();
        int nCols = md.getColumnCount();
        return (nCols);
    }
}

Related

  1. getResultSetDateValue(ResultSet rs, String sColumnName)
  2. GetResultSetFromQuery(String command)
  3. getResultSetFromQueryAgainstDefaultConnection( String sql)
  4. getResultSetInstance(Connection conn, String sql)
  5. getResultSetMetaData(ResultSet rs)
  6. getResultSetStrings(ResultSet rs)
  7. getResultSetValue(ResultSet rs, int index)
  8. getResultSetValue(ResultSet rs, int index)
  9. getResultSetValue(ResultSet rs, int index, Class requiredType)