Java SQL Table Column getRange(Connection C, String table, String column)

Here you can find the source of getRange(Connection C, String table, String column)

Description

get Range

License

Open Source License

Declaration

public static double[] getRange(Connection C, String table, String column) 

Method Source Code


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

import java.sql.*;

public class Main {
    public static double[] getRange(Connection C, String table, String column) {

        String query = "";
        Statement S;/*from   www. j  a  v a  2  s. c om*/
        ResultSet R;

        double[] range = new double[2];

        try {
            query = "SELECT MIN(" + column + "), MAX(" + column + ") FROM " + table + ";";
            S = C.createStatement();
            R = S.executeQuery(query);

            if (R.next()) {
                range[0] = R.getDouble(1);
                range[1] = R.getDouble(2);
            }

            R.close();
            S.close();

        } // end try
        catch (SQLException E) {
            System.out.println("SQLException: " + E.getMessage());
            System.out.println("SQLState:     " + E.getSQLState());
            System.out.println("VendorError:  " + E.getErrorCode());
        } // end catch

        return range;

    }

    public static double[] getRange(Connection C, String table, String column, String selection) {

        String query = "";
        Statement S;
        ResultSet R;

        double[] range = new double[2];

        try {
            query = "SELECT MIN(" + column + "), MAX(" + column + ") FROM " + table + " WHERE (" + selection + ");";
            S = C.createStatement();
            R = S.executeQuery(query);

            if (R.next()) {
                range[0] = R.getDouble(1);
                range[1] = R.getDouble(2);
            }

            R.close();
            S.close();

        } // end try
        catch (SQLException E) {
            System.out.println("SQLException: " + E.getMessage());
            System.out.println("SQLState:     " + E.getSQLState());
            System.out.println("VendorError:  " + E.getErrorCode());
        } // end catch

        return range;

    }
}

Related

  1. getColumnValue(String column, String defaultValue, Map columnIndexMap, ResultSet res)
  2. getColumnValueFromResultSet(int columnIndex, int argType, ResultSet rs)
  3. getColunmNames(ResultSetMetaData rsmd)
  4. getIndexColumns(Connection connection, String schema, String table, String indexName)
  5. getIndexName(Connection conn, String table, String column)
  6. hasColumn(final ResultSet row, final String columnName)
  7. hasColumn(ResultSet rs, String columnName)
  8. hasColumn(ResultSet rs, String columnName)
  9. hasColumn(String columnName, ResultSet resultSet)