Java SQL Table getTableFields(Connection con, String tableName)

Here you can find the source of getTableFields(Connection con, String tableName)

Description

get Table Fields

License

Apache License

Declaration

public static List<String> getTableFields(Connection con, String tableName) throws SQLException 

Method Source Code


//package com.java2s;
/*/* w  w  w  . j a v  a 2 s  .com*/
 * codjo.net
 *
 * Common Apache License 2.0
 */

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<String> getTableFields(Connection con, String tableName) throws SQLException {
        List<String> tableList = new ArrayList<String>();

        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("select * from " + tableName + " where 1=0");
        try {
            ResultSetMetaData rsmd = rs.getMetaData();
            int columnCount = rsmd.getColumnCount();
            for (int i = 1; i <= columnCount; i++) {
                tableList.add(tableName + "." + rsmd.getColumnName(i));
            }
        } finally {
            rs.close();
            stmt.close();
        }
        return tableList;
    }
}

Related

  1. getMetaDataMap(Statement statement, String tableOrViewName)
  2. getNextId(Connection con, String table, String identityFieldName)
  3. getRowCount(Statement stmt, String tableName)
  4. getSensorsList( final Connection jdbcConnection, String tableName)
  5. getShapeText(Connection conn, String tableName)
  6. getTableList(Connection connection)
  7. getTableName(String sql)
  8. getTableNames(Connection conn)
  9. getTableNames(Connection conn)