java - Freeze a gui jdbc ,when save a data,why? -


hy create 1 project (i maked using turtorial: http://www.homeandlearn.co.uk/java/save_a_new_record.html using database: http://www.homeandlearn.co.uk/java/java_and_databases.html)

when want save new record program freezing.(i want when save new data program able wrok next , prev buttons)

the save_button changed these code:

private void btnsaverecordactionperformed(java.awt.event.actionevent evt) {     //...................................................................................     string first = textfirstname.gettext();     string last = textlastname.gettext();     string job = textjobtitle.gettext();     string id = textid.gettext();     int newid = integer.parseint(id);      try {         string insertsql = "insert workers (id,first_name,last_name,job_title) values(" + newid + ",'" + first + "','" + last + "','" + job + "')";         stmt.executeupdate(insertsql);           rs.next();         int id_col = rs.getint("id");         string id = integer.tostring(id_col);         string first2 = rs.getstring("first_name");         string last2 = rs.getstring("last_name");         string job2 = rs.getstring("job_title");          textid.settext(id);         textfirstname.settext(first2);         textlastname.settext(last2);         textjobtitle.settext(job2);      } catch (sqlexception err) {         system.out.println(err.getmessage());     } 

(cleared blocking segment(false,trues..) have error:

resultset not open. operation 'next' not permitted. verify autocommit off.

)

the freezing because doing jdbc call in thread of ui. should never that, instead create new thread , execute work there.

when updating ui, don't call swing methods directly, use swingutilities.invokelater()

the error because you're doing insert, seem expect select. in tutorial, doing 'select' result, hence resultset. you're doing insert, doesn't have result, explains error when you're calling next. add following, under executeupdate() , work:

string sql = "select * workers"; rs = stmt.executequery(sql); 

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 -