Here you can find the source of getColumnNames(String tablename, String column, Connection conn)
static public List getColumnNames(String tablename, String column, Connection conn) throws SQLException
//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; } }