Home:ALL Converter>Java getColumLabel and getColumnName not working correctly

Java getColumLabel and getColumnName not working correctly

Ask Time:2015-07-20T17:14:58         Author:Peter

Json Formatter

I have this query:

select a.id AS testid, b.id as test2id from connector a LEFT JOIN connector_status b ON a.id = b.id where a.id = 99999

I want to retrieve metadata from the resultset with this code:

Statement st = conn.createStatement();
st.setMaxRows(1);
ResultSet rs  = st.executeQuery(query);
ResultSetMetaData meta = rs.getMetaData();
int columns = meta.getColumnCount();
for (int i = 1; i <= columns; i++) {
    System.out.println("Name: " + meta.getColumnName(i));
    System.out.println("Label: " + meta.getColumnLabel(i));
}

I get this result:

Name: testid
Label: testid
Name: test2id
Label: test2id

What am I doing wrong? getColumnName() should return id, or am I wrong?

Best regards Peter

Author:Peter,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/31512747/java-getcolumlabel-and-getcolumnname-not-working-correctly
yy