Hello, can anyone explain me why I'm still one step behind with this code?
private void jTextField1KeyPressed(java.awt.event.KeyEvent evt) {
try {
DefaultTableModel model=(DefaultTableModel)jTable1.getModel();
model.setNumRows(0);
String Name=jTextField1.getText();
String sql= "SELECT * FROM APP.Workers WHERE First_Name LIKE'" +Name+ "%'";
rs= stmt.executeQuery(sql);
while (rs.next()) {
String d1=(rs.getString("First_Name"));
String d2=(rs.getString("Last_Name"));
String d3=(rs.getString("Job_Title"));
String d4=(Integer.toString(rs.getInt("ID")));
model.addRow(new Object[]{d1,d2,d3,d4});
}
} catch (SQLException err) {
JOptionPane.showMessageDialog(Workers.this, err.getMessage());
}
}
I want to check what user write in TextField and then show matching records in Table. But, when I write to that TextField I'm one step behind- when I type first character nothing happens, when I type second it checks first character (and add matching records to the table) and so on...