This is a reusable code written in Java with a simple User Defined Method. User can just call the methods with the proper inputs and return values.
import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; import java.sql.Statement; import java.util.ArrayList; public class UserHelper { private ArrayList getFieldNames(String tableName) throws CCDBException { String SchemaName ="OPTUAT"; Connection conn = null; Statement stmt = null; ResultSet rs = null; DatabaseMetaData dmd = null; ArrayList fieldNames = new ArrayList(); try { conn = DBManager.getConnection(); dmd = conn.getMetaData(); rs = dmd.getColumns(null,null,tableName,null); while(rs.next()){ String d = rs.getString(4); fieldNames.add(d); } } catch (Exception e) { e.printStackTrace(); }finally { DBManager.cleanUp(rs, stmt, conn); } return fieldNames; } public static void main(String[] args) throws CCDBException{ } }