我想知道您是否可以使用getColumnDisplaySize()
生成一个更整洁的表格,并将结果放在正确的列中,我该怎么做?
这是我目前的代码。
stmt = con.createStatement();
ResultSet res = stmt.executeQuery("SELECT * FROM Orders ORDER BY OrderID");
if (res.next()) {
ResultSetMetaData rsmd = res.getMetaData();
int columnCount = rsmd.getColumnCount();
for (int i = 1; i <= columnCount; i++) {
columnHeading = columnHeading + "\t" + rsmd.getColumnName(i);
}
System.out.println(columnHeading);
do {
for (int i = 1; i <= columnCount; i++) {
System.out.print("\t" + res.getString(i));
}
System.out.println("\n");
} while(res.next());
}