java - How can I validate my database entry through swing? -


i have written code insert information mysql database. mobile number , email can not duplicate while entering data. can implement 1 resultset, don't know how implement multiple result set.

here code:

public void actionperformed(actionevent evt) {  dbcon db = new dbcon(); connection conn = null; statement stmt = null; resultset rs= null; try{       class.forname("com.mysql.jdbc.driver");      conn = drivermanager.getconnection(db.db_url, db.user, db.pass);     stmt = conn.createstatement();      rs= stmt.executequery("select email student_info email= '" + email_txt.gettext()+"'" );     rs = stmt.executequery("select mob student_info mob= '" + ph_txt.gettext()+"'" );   // i'm not getting error, here problem      if(rs.next()){     joptionpane.showmessagedialog(null,"email id exists");     email_txt.settext("");     }      else if(rs.next()){          joptionpane.showmessagedialog(null,"contact number exists");         ph_txt.settext("");      }      {       string qry = "insert student_info(nam, email, mob, country, city, sex) values(?,?,?,?,?,?)";      preparedstatement pst = conn.preparestatement(qry);     string comval = country_txt.getselecteditem().tostring();       pst.setstring(1, name_txt.gettext());     pst.setstring(2, email_txt.gettext());     pst.setstring(3, ph_txt.gettext());     pst.setstring(4, comval);        pst.setstring(5, city_txt.gettext());     pst.setstring(6, sex_txt.gettext());       pst.execute();     joptionpane.showmessagedialog(null, "successfully added records");      rs.close();     pst.close();     conn.close();      }      }     catch(exception e)     {         joptionpane.showmessagedialog(null, e);        } } });  

can use multiple resultset checking duplicate entry?


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -