java - swing wait 3 second inside while loop -
this question exact duplicate of:
- swing retrieve data mysql db textfield 2 answers
i have program data mysql db , show in textfield.
i want show 1 record every 3 second.
this code,
connection conn = null; statement st = null; resultset rs = null; string dburl = "jdbc:mysql://localhost:3306/jointdb"; string dbusr = "root"; string dbpass = "a12345"; try{ string sql= "select * eridb "; class.forname("com.mysql.jdbc.driver"); conn = drivermanager.getconnection (dburl,dbusr,dbpass); st = conn.createstatement(); rs = st.executequery(sql); // textfield1.settext("enter text here"); while(rs.next()){ string value = rs.getstring("id"); textfield1.settext(value); } }catch(exception e){ e.printstacktrace(); }finally{ try { rs.close(); } catch (sqlexception e) { e.printstacktrace(); } try { st.close(); } catch (sqlexception e) { e.printstacktrace(); } try { conn.close(); } catch (sqlexception e) { e.printstacktrace(); } }
i have used sleep, program hanging ( no benefits)
please assist me thank ...
if want background jobs take time in swing, should use swingworker
(oracle's tutorial, although not helpful... ).
for scheduling task, can go, @andrew thompson said javax.swing.timer
(a better tutorial oracle time.
Comments
Post a Comment