You may refer the below code:
 ResultSet r = stmt.executeQuery("SELECT x, y, z FROM TABLE2");
 ResultSetMetaData rmd = r.getMetaData();
 String name = rmd.getColumnName(1);
and you can get the column name from there. If you do
select a as b from table
then rmd.getColumnLabel() will get you the retrieved label name too.