在java中查看mysql查询的结果

时间:2010-11-20 14:42:28

标签: java mysql

在java中,执行如下的查询时:

语句stm = stm.executeQuery(“select * from table1”);

如何在命令提示符下查看此查询的结果?

感谢您的帮助

1 个答案:

答案 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