我有这个问题:
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
我想使用以下代码从结果集中检索元数据:
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));
}
我得到了这个结果:
Name: testid
Label: testid
Name: test2id
Label: test2id
我做错了什么? getColumnName()应该返回id,还是我错了?
祝你好运 彼得
答案 0 :(得分:0)
a.id被别名为testid。因为否则&#34; id&#34; 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
中的含糊不清。
getColumnName()返回&#34; testid&#34;因为别名&#34; testid&#34;。