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