java - Freezed program after delete record(GUI) -


this code:

  private void btndeleterecordactionperformed(java.awt.event.actionevent evt) {                                                     // todo add handling code here:     try {         rs.deleterow();         stmt.close();         rs.close();          stmt = con.createstatement(resultset.type_scroll_sensitive,                 resultset.concur_updatable);          string sql = "select * workers";         rs = stmt.executequery(sql);          rs.next();         int id_col = rs.getint("id");         string id = integer.tostring(id_col);         string first = rs.getstring("first_name");         string last = rs.getstring("last_name");         string job = rs.getstring("job_title");          textid.settext(id);         textfirstname.settext(first);         textlastname.settext(last);         textjobtitle.settext(job);     } catch (sqlexception err) {         //  system.out.println(err.getmessage());         joptionpane.showmessagedialog(workers.this, err.getmessage());     }  }          

aftei delete 1 row database program freeze. want program able work after delete button te next , prevrious button work.

i used thie: http://www.homeandlearn.co.uk/java/delete_a_record_from_a_database.html

firstly:

rather define statement , resultset within method doing work, better use of scope , safer when working multi-threaded code...

secondly:

when querying "workers", map each row pojo , put pojo's in collection, have app work collection instead of resultset.

thirdly:

when doing update/delete, create update/delete statement , use entries (you trying modify's) id (or other type of unique reference) statement.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -