【求助】关于JTable列表显示的问题
怎样在JTable中显示数据表中符合某条件的记录如显示changeRoom表中入住单号(ruZhuDanNum)为 “人为输入的任意值”(由textfield输入) 的一条或几条记录?、
我自己写的代码如下,麻烦看看有什么问题帮忙改一下 不胜感激
public static ArrayList<Object[]> search(String ruZhuDanNum){
‘
ArrayList<Object[]> l = new ArrayList<Object[]>();
String sql = "select * from changeRoom where ruZhuDanNum =‘ " + ruZhuDanNum +"'";
Connection con = Test.getCon();
try {
Statement stat = con.createStatement();
ResultSet rs = stat.executeQuery(sql);
while(rs.next()){
Object[] obj = new Object[3];
obj[0] = rs.getObject(1);
obj[1] = rs.getObject(2);
obj[2] = rs.getObject(3);
l.add(obj);
}
rs.close();
stat.close();
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return l;
}
public void actionPerformed(ActionEvent e) {
ArrayList<Object[]> l = ChangeRoomDan.search(ruzhuNumtxt.getText);
DefaultTableModel model = new DefaultTableModel();
model.addColumn("编号");
model.addColumn("入住单编号");
model.addColumn("房间类型");
for(Object[] o : l){
System.out.println(o[0]+" "+o[1]+" "+o[2]+" "+o[3]);
model.addRow(o);
}
table.setModel(model);
}
jtable java
补充:Java , Eclipse