Java SQL ResultSet Read getResult(ResultSet rs)

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

Description

get Result

License

BSD License

Parameter

Parameter Description
rs Result set to process

Exception

Parameter Description
SQLException if some error occurred while processing result set

Return

String[][] created by getting all records of result set

Declaration

private static String[][] getResult(ResultSet rs) throws SQLException 

Method Source Code

//package com.java2s;
/*L//  ww  w. jav  a  2 s.c  o  m
 * Copyright Georgetown University, Washington University.
 *
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/cab2b/LICENSE.txt for details.
 */

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

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**
     * @param rs Result set to process
     * @return String[][] created by getting all records of result set
     * @throws SQLException if some error occurred while processing result set
     */
    private static String[][] getResult(ResultSet rs) throws SQLException {
        List<String[]> results = new ArrayList<String[]>();
        int noOfColumns = rs.getMetaData().getColumnCount();

        while (rs.next()) {
            String[] oneRow = new String[noOfColumns];
            for (int i = 1; i <= noOfColumns; i++) {
                oneRow[i - 1] = rs.getString(i);
            }
            results.add(oneRow);
        }

        return results.toArray(new String[0][0]);
    }
}

Related

  1. getObjectByTypeCoercion(ResultSet resultSet, int index, int dataType)
  2. getOjbClassName(ResultSet rs)
  3. getOptionalInt(ResultSet rs, String name)
  4. getPath(ResultSet r, String columnName)
  5. getRecordsFromResultSet(ResultSet rs)
  6. getResultArray(ResultSet resultSet, int size, java.util.Date startDate)
  7. getResultByMap(ResultSet rs)
  8. getResults(ResultSet result)
  9. getResultsAsMap(ResultSet rs)