Java JDBC Database Metadata getColumns(Connection connection, String name)

Here you can find the source of getColumns(Connection connection, String name)

Description

get Columns

License

Open Source License

Declaration

public static ResultSet getColumns(Connection connection, String name) throws SQLException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015 SAP and others.//ww  w . j  a v a 2s  . c  om
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * Contributors:
 * SAP - initial API and implementation
 *******************************************************************************/

import java.sql.Connection;
import java.sql.DatabaseMetaData;

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

public class Main {
    public static ResultSet getColumns(Connection connection, String name) throws SQLException {

        DatabaseMetaData meta = connection.getMetaData();

        if (name == null) {
            meta.getColumns(null, null, name, null);
        }

        ResultSet columns = meta.getColumns(null, null, name, null);
        if (columns.next()) {
            return meta.getColumns(null, null, name, null);
        } else {
            columns = meta.getColumns(null, null, name.toLowerCase(), null);
            if (columns.next()) {
                return meta.getColumns(null, null, name.toLowerCase(), null);
            } else {
                columns = meta.getColumns(null, null, name.toUpperCase(), null);
                // if (columns.next()) {
                // return meta.getColumns(null, null, name.toUpperCase(), null);
                // }
            }
        }

        return columns;
    }
}

Related

  1. getAllTables(Connection connection)
  2. getCatalogs(Connection c)
  3. getColumnDefaultValue(DatabaseMetaData metaData, String tableName, String columnName)
  4. getColumnNames(Connection connection, String tableName)
  5. getColumnNames(String tablename, String column, Connection conn)
  6. getColumnSize(Connection con, String tableName, String columnName)
  7. getDatabaseId(DatabaseMetaData md)
  8. getDatabaseInfo(Connection connection_)
  9. getDatabaseMetaData(Connection con)