java - While ResultSet is not executing? -
i trying call 2 sets of data 2 different tables display in jtextarea (jtadisplay
). first table (emp_db
) employee number, name , surname. second table (sec_clearance
) employee security clearance level.
the method placed in constructor execute when frame starts up, whenever run frame not display data. no error messages come , stack trace doesn't display error messages.
i placed joptionpane in various places inside method see problem lies , found while(rs.next())
statement not executing joptionpane displays outside while
statement not inside it.
here code have:
try { string user = txtemptitle.gettext(); string encuser = encrypt(user); //encrypting employee number aes read in database string getempnum = "select * emp_db emp_num = '" + encuser + "'"; string getseclevel = "select seclevel sec_clearance emp_num = '" + encuser + "'"; class.forname("com.mysql.jdbc.driver"); connection conn = (connection) drivermanager.getconnection("jdbc:mysql://localhost:3306/employee_database","root","pass123"); statement stmt=conn.createstatement(); statement stmt2=conn.createstatement(); resultset rs = stmt.executequery(getempnum); resultset rs2 = stmt2.executequery(getseclevel); while(rs.next() && rs2.next()) { string empnum = rs.getstring("emp_num"); string empname = rs.getstring("fname"); string empsname = rs.getstring("sname"); string empseclevel = rs2.getstring("seclevel"); //decrypting data in database string decnum = empeditdb.decrypt(empnum); string decname = empeditdb.decrypt(empname); string decsname = empeditdb.decrypt(empsname); string decseclevel = empeditdb.decrypt(empseclevel); jtadisplay.settext("employee number: " + decnum + "\nemployee name: " + decname + " " + decsname + "\nsecurity clearance: " + decseclevel); } } catch(exception e) { joptionpane.showmessagedialog(this, e); }
how can code in while statement execute , display data in jtextarea?
only if have record ,it come while loop.better use preparedstatement dynamic value setting.for debugging purpose try print query in debugging , copy query , execute in sql tool checking whether records.
Comments
Post a Comment