jdbc - -> java.sql.SQLException: Exhausted Resultset -


private void jbutton1actionperformed(java.awt.event.actionevent evt) {      if (evt.getsource() == jbutton1) {          string ab = jtextfield1.gettext();         string bc = jpasswordfield1.gettext().tostring();         string cd = jtextfield2.gettext();         string de = jtextfield3.gettext();         preparedstatement ps1 = null;         preparedstatement ps = null;         resultset rs = null;         try {             class.forname("oracle.jdbc.driver.oracledriver");             connection c = drivermanager.getconnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "hr");             ps = c.preparestatement("select user_name adminlogin password =?");             ps.setstring(1, bc);              rs = ps.executequery();             rs.next();              if (ab.equals(rs.getstring(1))) {                  ps1 = c.preparestatement("update adminlogin set date1=?,time=? password=?");                 ps1.setstring(1, cd);                 ps1.setstring(2, de);                 ps1.setstring(3, bc);                 int e = ps1.executeupdate();                 joptionpane.showmessagedialog(this, "welcome", "logged in", joptionpane.information_message);                 //mainmenuaai mainmenuaai = new mainmenuaai();                 //setvisible(false);}             } else if (!(ab.equals(rs.getstring(1)))) {                 joptionpane.showmessagedialog(this, "<html>you not a<br>admin</br></html>", "error", joptionpane.error_message);                 //adminlogin admin=new adminlogin();                 //setvisible(false);             }              c.close();         } catch (exception e) {              system.out.println(e);         }     }// todo add handling code here: } 

everything working fine in code. executing code inside

if(ab.equals(rs.getstring(1))) 

and showing "welcome" not d 1 inside

if(!(ab.equals(rs.getstring(1)))) 

whenever enter wrong username or password shows error

java.sql.sqlexception: exhausted resultset

that correct, because if enter wrong username or password, no record returned. so, when use rs.next(); in case, trying access first row of empty result set! , throwing exception.

you fix code this:

rs = ps.executequery(); //rs.next(); int counter=0; while (rs.next()) {     counter++;     if (ab.equals(rs.getstring(1))) {         ps1 = c.preparestatement("update adminlogin set date1=?,time=? password=?");         ps1.setstring(1, cd);         ps1.setstring(2, de);         ps1.setstring(3, bc);         int e = ps1.executeupdate();         joptionpane.showmessagedialog(this, "welcome", "logged in", joptionpane.information_message);         //mainmenuaai mainmenuaai = new mainmenuaai();         //setvisible(false);}     }  } if(counter==0){     joptionpane.showmessagedialog(this, "<html>you not a<br>admin</br></html>", "error", joptionpane.error_message); } 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -