This question already has an answer here:
- Retrieve column names from java.sql.ResultSet 11 answers
I want to get all the column names for a specific table called Impedance2, in an Access database I have. I can only seem to get column metadata I think rather than the actual name:
This is the code I am using:
DatabaseMetaData md = conn.getMetaData();
ResultSet rst = md.getTables(null, null, "Impedance2", null);
ResultSetMetaData rsmd = rst.getMetaData();
System.out.println("Column names as reported by ResultSetMetaData:");
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
System.out.println("Col"+rsmd.getColumnName(i));
}
This is the result I am getting:
ColTABLE_CAT
ColTABLE_SCHEM
ColTABLE_NAME
ColTABLE_TYPE
ColREMARKS
ColTYPE_CAT
ColTYPE_SCHEM
ColTYPE_NAME
ColSELF_REFERENCING_COL_NAME
ColREF_GENERATION
ColHSQLDB_TYPE
ColREAD_ONLY
ColCOMMIT_ACTION