java在图形界面显示数据库中的数据问题?

2024-12-27 09:20:09
推荐回答(2个)
回答1:

public JMenu getJMenu2(String tit1) {
JMenu jmu = new JMenu();
jmu.setText(tit1);
jmit2 = new JMenuItem("查询");
jmit2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {
Statement stmt = null;
ResultSet rs = null;
final String[] colHeads = {"编 号", "账 号", "密 码", "性 别", "学 历", "爱 好", "Email", "Q Q", "生 日"};
Object[][] base = new Object[10][9];
JFrame jf = new JFrame();
JPanel jpl = new JPanel();
try {
con = Sqlsever.getDatabase(con);
stmt = con.createStatement();

int i = 0;

rs = stmt.executeQuery("select * from member");

while (rs.next()) {
base[i][0] = rs.getInt("memID");
base[i][1] = rs.getString("memNum");
base[i][2] = rs.getString("memPsw");
base[i][3] = rs.getString("memSex");
base[i][4] = rs.getString("memSch");
base[i][5] = rs.getString("memLike");
base[i][6] = rs.getString("memEmail");
base[i][7] = rs.getString("memQQ");
base[i][8] = rs.getString("memBtday");
i++;
}

} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (SQLException e1) {
e1.printStackTrace();
}

JTable table = new JTable(base, colHeads);
table.setPreferredScrollableViewportSize(new Dimension(600, 100));//设置表格的大小

JScrollPane pane3 = new JScrollPane(table);

jpl.setPreferredSize(new Dimension(600, 400));
jpl.add(pane3);

JLabel pitLabel1 = new JLabel(new ImageIcon("images/bg1.jpg"));
pitLabel1.setBounds(0, -10, 600, 500);
jpl.add(pitLabel1);

jf.setContentPane(jpl);

jf.setIconImage(new ImageIcon("images/icon.gif").getImage());
jf.pack();
jf.show();

}
});

回答2:

你的return呢?
还有无论你用的是servlet还是现在的Struts框架,都要把数据保存到
请求或者是session中去啊