【发布时间】:2023-12-21 14:01:02
【问题描述】:
我正在 Eclipse 中执行一个项目。我的导航按钮运行良好。但是,我的表单中还有一个JTable 来执行搜索,我可以显示从Jtable 到我的Jtextfields 的记录。问题是,在我执行搜索并单击任何导航按钮后,它会显示“不再记录”。
这是我的搜索代码:
txtsearch = new JTextField();
txtsearch.setBounds(723, 85, 150, 25);
add(txtsearch);
txtsearch.addKeyListener(new KeyAdapter(){
public void keyReleased(KeyEvent e){
String Query3 = "Select * from customer where CustCompanyName = ?";
try {
stt = con.prepareStatement(Query3);
stt.setString(1, txtsearch.getText());
rs = stt.executeQuery();
table2.setModel(DbUtils.resultSetToTableModel(rs));
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
这是我在文本字段中显示的代码:
table2.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
try {
int Row = table2.getSelectedRow();
String ccode = (table2.getModel().getValueAt(Row, 0).toString());
String Query4 = "Select * from customer where CustomerCode = '"+ccode+"'";
stt = con.prepareStatement(Query4);
rs=stt.executeQuery();
while(rs.next()) {
txtcode.setText(rs.getString("CustomerCode"));
txtcompname.setText(rs.getString("CustCompanyName"));
txtaddress.setText(rs.getString("CustAddress"));
txtpnumber.setText(rs.getString("CustPhoneNumber"));
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
【问题讨论】:
-
'它说'...说什么?您发布的当前代码中没有任何内容定义短语“不再记录”,您的代码中也没有定义“按钮”。
-
我只发布了在文本字段中搜索和显示的代码.. 在我的 Eclipse 中我已经声明了所有内容.. 在我的导航按钮中找到了“没有更多记录”:
-
@Aalm :你看到我的回答了吗?
标签: java swing jtable jtextfield