rs = stmt.executeQuery(querySQL1);
// 提取结果集的元数据:
ResultSetMetaData rsmd = rs.getMetaData();
int colCount = rsmd.getColumnCount();
String[] columnNames = new String[colCount];
String[] columnLabels = new String[colCount];
int[] columnTypes = new int[colCount];
for (int i = 0; i < colCount; i++) {
columnNames[i] = rsmd.getColumnName(i + 1);
columnLabels[i] = rsmd.getColumnLabel(i + 1);
columnTypes[i] = rsmd.getColumnType(i + 1);
}
System.out.println();
System.out.println("提取的数据如下:");
System.out.println();
System.out .println("----------------------");
for (int i = 0; i < colCount; i++) {
System.out.print(columnLabels[i] + "\t");
System.out.println();
for (int i = 0; i < colCount; i++) {
System.out.print(columnNames[i] + "\t");
}
} catch (NamingException ex) {
System.err.println("Name Not Bound : " + ex.getMessage());
} catch (SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
} finally {
try {
if (con != null)
con.close();
} catch (Exception e) {
}
}
System.out.println("程序结束!!!");
}
}
摘自 Java教程