Java SQL ResultSet Print printView(ResultSet rs)

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

Description

print View

License

Apache License

Declaration

public static String printView(ResultSet rs) throws Exception 

Method Source Code

//package com.java2s;
/*/*from  w ww.ja  va  2s.  c  o m*/
 // Licensed to DynamoBI Corporation (DynamoBI) under one
 // or more contributor license agreements.  See the NOTICE file
 // distributed with this work for additional information
 // regarding copyright ownership.  DynamoBI licenses this file
 // to you under the Apache License, Version 2.0 (the
 // "License"); you may not use this file except in compliance
 // with the License.  You may obtain a copy of the License at

 //   http://www.apache.org/licenses/LICENSE-2.0

 // Unless required by applicable law or agreed to in writing,
 // software distributed under the License is distributed on an
 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
 */

import java.sql.*;
import java.util.*;
import javax.management.openmbean.*;

public class Main {
    public static String printView(ResultSet rs) throws Exception {
        ResultSetMetaData rsMetaData = rs.getMetaData();
        int numCols = rsMetaData.getColumnCount();
        String[] headers = new String[numCols];
        OpenType[] allTypes = new OpenType[numCols];
        Vector[] values = new Vector[numCols];
        Object[] allValues = new Object[numCols];

        String ret = "";

        for (int i = 0; i < numCols; i++) {
            if (i == 0) {
                ret = rsMetaData.getColumnName(i + 1);
            } else {
                ret = ret + "," + rsMetaData.getColumnName(i + 1);
            }
        }
        ret = ret + "\n";

        while (rs.next()) {
            for (int i = 0; i < numCols; i++) {
                if (i == 0) {
                    ret = ret + rs.getString(i + 1);
                } else {
                    ret = ret + ", " + rs.getString(i + 1);
                }
            }
            ret = ret + "\n";
        }

        return ret;
    }
}

Related

  1. printResultsToFile(ResultSet rst, File outFile)
  2. printRow(ResultSet pk)
  3. printRsetTypeAndConcurrencyType(ResultSet rset)
  4. printSet(ResultSet set, int columns)
  5. printValues(final ResultSet resultSet)
  6. printWarnings(ResultSet resultSet)