public static void PrintAllSql throws SQLException res = smtexecuteQueryselect from student; while resnext Systemoutprintln学号: + resgetStringSno + 姓名: + resgetStringSname + 性别: + resgetStringSsex +
你可以使用一个字符串变量来存储查询结果,然后将其显示在一个弹窗上。例如:
public static void PrintAllSql() throws SQLException { res = smt.executeQuery("select * from student"); String output = ""; while (res.next()) { output += "学号:" + res.getString("Sno") + "姓名:" + res.getString("Sname") + "性别:" + res.getString("Ssex") + "年龄:" + res.getString("Sage") + "备注:" + res.getString("Sremark") + "\n"; } JOptionPane.showMessageDialog(null, output); }
这个方法将查询结果以字符串的形式存储在变量output中,然后调用JOptionPane的showMessageDialog方法,将output的内容显示在一个弹窗中
原文地址: https://www.cveoy.top/t/topic/fFcY 著作权归作者所有。请勿转载和采集!