Java SQL ResultSet consume(ResultSet rs)

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

Description

consume

License

Open Source License

Declaration

private static Object[][] consume(ResultSet rs) throws Exception 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * xFramium//from   ww w .  ja  v  a  2  s . com
 *
 * Copyright 2016 by Moreland Labs, Ltd. (http://www.morelandlabs.com)
 *
 * Some open source application 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 3 of the License, or (at your option) any later version.
 *  
 * Some open source application 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 xFramium.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>
 *******************************************************************************/

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

public class Main {
    private static Object[][] consume(ResultSet rs) throws Exception {
        ResultSetMetaData rsmd = rs.getMetaData();
        ArrayList results = new ArrayList();
        int colCount = rsmd.getColumnCount();

        while (rs.next()) {
            Object[] row = new Object[colCount];

            for (int i = 1; i <= colCount; ++i) {
                row[i - 1] = rs.getObject(i);
            }

            results.add(row);
        }

        return toOutArray(results, colCount);
    }

    private static Object[][] toOutArray(List listOfArray, int colCount) {
        int length = listOfArray.size();
        Object[][] rtn = new Object[length][colCount];

        for (int i = 0; i < rtn.length; ++i) {
            rtn[i] = (Object[]) listOfArray.get(i);
        }

        return rtn;
    }
}

Related

  1. arrayOfResult(ResultSet rs)
  2. cleanupAfterQuery(final ResultSet rs, final Statement stmt)
  3. cleanupConnection(ResultSet rs, Statement stmt, Connection conn)
  4. cleanupJDBCResouce(ResultSet rs, Statement stmt, String oldCatalog, Connection conn)
  5. consume2(ResultSet rs)
  6. copyInt(ResultSet rs, int sourcePos, PreparedStatement stmt, int destPos)
  7. createLargeResultSetPreparedStatement(Connection conn, String sql)
  8. createLargeResultSetStatement(Connection conn)