Java 使用 JOptionPane 显示 SQL 查询结果
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/ok43 著作权归作者所有。请勿转载和采集!