Hello everyone, I am fresh in java world and I stucked with searching database. So, my application is connected to msacces and my Jframe has jtable and some textfield's. I have one textfield which is called Searchfield and when I press some number in that field its searching database and if i pressed 5 its showing student with ID 5. My problem is next, I created button which random generating numbers (1-34) and writing them into Searchfield, but when Searchfield gets that random generated number nothing happening. Thanks in advance for reading this.
This is part of code for searching by ID:
private void txtsearchKeyReleased(java.awt.event.KeyEvent evt) {
//search by ID
String temp = txtsearch.getText() + "%";
String sql = "select * from table1 where ID like'"+temp+"'";
try{
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
}
catch (Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
That works just like it should , but i dont know how to set this:
private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {
// random number 1-34
Random randomnumb = new Random();
int number = 1 + randomnumb.nextInt(34);
txtsearch.setText(String.valueOf(number));
Its only show number in searchfield, nothing else (not searching DB)