Java SQL ResultSet Read getData(final ResultSet rs)

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

Description

Get a ResultSet's result.

License

Open Source License

Parameter

Parameter Description
rs ResultSet

Exception

Parameter Description
SQLException on SQL problems

Return

two-dimensional Array containing the results

Declaration

public static Object[][] getData(final ResultSet rs) throws SQLException 

Method Source Code


//package com.java2s;
/* JAPI - (Yet another (hopefully) useful) Java API
 *
 * Copyright (C) 2004-2006 Christian Hujer
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA./*from  www . j  ava  2s .c  o m*/
 */

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

public class Main {
    /** The Type information for a two-dimensional Object Array. */
    private static final Object[][] OBJECT_ARRAY_ARRAY_INSTANCE = new Object[0][0];

    /** Get a ResultSet's result.
     * @param rs ResultSet
     * @return two-dimensional Array containing the results
     * @throws SQLException on SQL problems
     */
    public static Object[][] getData(final ResultSet rs) throws SQLException {
        final List<Object[]> resultList = new ArrayList<Object[]>();
        final ResultSetMetaData md = rs.getMetaData();
        final int columnCount = md.getColumnCount();
        while (rs.next()) {
            final Object[] row = new Object[columnCount];
            for (int i = 0; i < columnCount; i++) {
                row[i] = rs.getObject(i + 1);
            }
            resultList.add(row);
        }
        return resultList.toArray(OBJECT_ARRAY_ARRAY_INSTANCE);
    }
}

Related

  1. getCalendar(ResultSet resultSet, String columnName)
  2. getCharacterStream(ResultSet resultSet, String columnName)
  3. getChunkDelimiters(ResultSet rs, int tsColumnIndex, int chunkSize)
  4. getClassName(ResultSetMetaData meta, int index)
  5. getCountFromResultSet(ResultSet rs)
  6. getDataDupls(ResultSet rs)
  7. getDateList(ResultSet resultSet, String columnName)
  8. getDbDateValue(ResultSet rs, String columnName)
  9. getDebugData(ResultSet rs)