How to get Total Columns Returned by Query
ResultSet rs = stmt.executeQuery(strSQL); ResultSetMetaData rsmd = rs.getMetaData(); int columnsNumber = rsmd.getColumnCount();
How to get Column Name from Query
ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
ResultSetMetaData rsmd = rs.getMetaData();
String name = rsmd.getColumnName(1);
How to get Column Count from Query and Loop Through That
ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
// The column count starts from 1
for (int i = 1; i < columnCount + 1; i++ ) {
String name = rsmd.getColumnName(i);
// Do stuff with name
}
To Find a Column with particular Name
ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
rs.getString(rs.findColumn("fullname"));
How to get List of Column Names from Query and Store it in a Array
ResultSetMetaData meta = resultset.getMetaData(); Integer columncount = meta.getColumnCount(); int count = 1 ; String[] columnNames = null; while(columncount <=count) columnNames [i] = meta.getColumnName(i); System.out.println (columnNames.size());