Extract column names in java from a dynamic sql query -
i want parse sql query , extract column names it. can't extract part between 'select' , 'from' because query can have alias. requirement now, later on type of query can come in, need dynamic method/ library return column names.
you need use resultsetmetadata
names of columns in result set returned after executing query.
resultset rs = stmt.executequery(...); resultsetmetadata rsmd = rs.getmetadata(); int columncount = rsmd.getcolumncount() (int = 1; < columncount; i++) { system.out.println(rsmd.getcolumnname(i)); }
note: index starts 1
, not 0
Comments
Post a Comment