我想知道如何使用 printf 方法为我的列创建标题:
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select country_id,country_name,region_id,last_name from countries");
while (rset.next())
System.out.printf("%-5s %-25s %5s \n", rset.getString("country_id"),rset.getString("country_name"),rset.getString("region_id"));
stmt.close();
conn.close();
输出是这样的,我想要每列上方的标题!我怎样才能做到这一点?
AR Argentina 2
AU Australia 3
BE Belgium 1
BR Brazil 2
CA Canada 2
CH Switzerland 1
CN China 3
DE Germany 1
DK Denmark 1
EG Egypt 4
FR France 1
IL Israel 4
IN India 3
IT Italy 1
JP Japan 3
KW Kuwait 4
ML Malaysia 3
MX Mexico 2
NG Nigeria 4
NL Netherlands 1
SG Singapore 3
UK United Kingdom 1
US United States of America 2
ZM Zambia 4
ZW Zimbabwe 4