Java JDBC Database Metadata getColumnNames(String tablename, String column, Connection conn)

Here you can find the source of getColumnNames(String tablename, String column, Connection conn)

Description

get Column Names

License

Open Source License

Declaration

static public List getColumnNames(String tablename, String column, Connection conn) throws SQLException 

Method Source Code


//package com.java2s;
/*//from   w ww  .ja v  a2  s  .c o  m
 * B3P Commons GIS is a library with commonly used classes for OGC
 * reading and writing. Included are wms, wfs, gml, csv and other
 * general helper classes and extensions.
 *
 * Copyright 2005 - 2008 B3Partners BV
 * 
 * This file is part of B3P Commons GIS.
 * 
 * B3P Commons GIS 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.
 * 
 * B3P Commons GIS 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 B3P Commons GIS.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Main {
    static public List getColumnNames(String tablename, String column, Connection conn) throws SQLException {
        DatabaseMetaData dbmd = conn.getMetaData();
        ResultSet rs = dbmd.getColumns(null, null, tablename, column);
        List columns = null;
        while (rs.next()) {
            String columnName = rs.getString("COLUMN_NAME");
            if (columns == null) {
                columns = new ArrayList();
            }
            columns.add(columnName);
        }
        return columns;
    }
}

Related

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