在java中,执行如下的查询时:
语句stm = stm.executeQuery(“select * from table1”);
如何在命令提示符下查看此查询的结果?
感谢您的帮助
答案 0 :(得分:4)
ResultSet rs = stmt.executeQuery("select * from table1");
int columns = rs.getMetaData().getColumnCount();
StringBuilder message = new StringBuilder();
while (rs.next()) {
for (int i = 1; i <= columns; i++) {
message.append(rs.getString(i) + " ");
}
message.append("\n");
}
System.out.println(message); // print table contents