Java SQL ResultSet Read getRows(final ResultSet rs)

Here you can find the source of getRows(final ResultSet rs)

Description

For SciDB, use getRowsSciDB instead This does not work with SciDB because for SciDB's JDBC reference to "getObject" invariably returns null.

License

Open Source License

Parameter

Parameter Description
rs a parameter

Exception

Parameter Description
SQLException an exception

Declaration

public static List<List<String>> getRows(final ResultSet rs) throws SQLException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Main {
    /**//from w w w.ja  va 2s  . c  o  m
     * For SciDB, use getRowsSciDB instead
     * This does not work with SciDB because for SciDB's JDBC reference to "getObject" invariably returns null. 
     * @param rs
     * @return
     * @throws SQLException
     */
    public static List<List<String>> getRows(final ResultSet rs) throws SQLException {
        if (rs == null) {
            return null;
        }
        List<List<String>> rows = new ArrayList<>();
        try {
            ResultSetMetaData rsmd = rs.getMetaData();
            int NumOfCol = rsmd.getColumnCount();
            while (rs.next()) {
                List<String> current_row = new ArrayList<String>();
                for (int i = 1; i <= NumOfCol; i++) {
                    Object value = rs.getObject(i);
                    if (value == null) {
                        current_row.add("null");
                    } else {
                        current_row.add(value.toString());
                    }
                }
                rows.add(current_row);
            }
            return rows;
        } catch (SQLException e) {
            throw e;
        }
    }
}

Related

  1. getResultSetValue(ResultSet rs, int index, Class requiredType)
  2. getReturnCountInt(ResultSet rs, int column)
  3. getRow(ResultSet rs)
  4. getRowCount(final ResultSet rs)
  5. getRowCount(ResultSet set)
  6. getRows(ResultSet table)
  7. getRsCloumns(ResultSet rs)
  8. getRSData(ResultSet rs, String columnName, int jdbcType)
  9. getStatement(ResultSet resultSet)