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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -