Can somebody tell me how focusgained method works?
I have a application in which as i enter the text in a textbox it should populate the jTable, My code takes 5 to 10 mins to populate the data, i use java netbeans and microsoft access database.
I have a application in which as i enter the text in a textbox it should populate the jTable, My code takes 5 to 10 mins to populate the data, i use java netbeans and microsoft access database.
Code:
jTextField1.addFocusListener(this); public void focusGained(FocusEvent e) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String filename = "C:/Users/Office User/Desktop/testfordb/test.mdb"; String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="; database+= filename.trim() + ";DriverID=22}"; Connection con = DriverManager.getConnection( database ,"",""); Statement st = con.createStatement(); // search String query1 = "select * from "+jTextField4.getText()+" where `U NAME` like '"+name.getText()+"%' "; ResultSet rs1 = st.executeQuery(query1); jTable1.setModel(DbUtils.resultSetToTableModel(rs1)); } catch (ClassNotFoundException | SQLException e) { e.printStackTrace(); System.out.println("Error: " + e); } } public void focusLost(FocusEvent e) { // Save the text }
Comment