java - my sql statement for update doesnt work -


i not able execute update statement. there seems issue update statement.

what i'm doing i'm trying update duplicated email address , replace (update) non-duplicated email. therefore, in order update, sql statement check database against input , if ((firstname && lastname && dateofbirth) || (phoneno && address) match user input, update database; is: update duplicated email address non-duplicated email, remove duplicated email after update has been executed.

however, i'm not able figure out what's wrong. here update statement:

 try {          system.out.println("it came here filepart!=null");             drivermanager.registerdriver(new com.mysql.jdbc.driver());         conn = drivermanager.getconnection(dburl, dbuser, dbpass);             // connects database             conn = getconnection();              // constructs sql statement           stmt = conn.createstatement();             //sqll should update             string sql1 ="update registration set emailaddress = ? ((firstname = ? && lastname= ? && dateofbirth= ?) || (phoneno= ? && address= ?))" ;              //using preparedstatement save file             preparedstatement statement1 = conn.preparestatement(sql1);             system.out.println(firstname+"firstname");             statement1.setstring(1, firstname);             statement1.setstring(2, lastname);           statement1.setstring(3, dateofbirth);              statement1.setstring(4, phoneno);           statement1.setstring(5, address);        statement1.executeupdate();        statement1.close();      string sql2="delete registration registration inner join (select min(userid) lastid, emailaddress registration emailaddress in ( select emailaddress  registration group emailaddress having count(*) > 1) group emailaddress) duplic on duplic.emailaddress = registration.emailaddress registration.userid > duplic.lastid";     stmt.executeupdate(sql2);                //sends statement database server             // if (row > 0) {               // getservletcontext().getrequestdispatcher("/message.jsp").include(request, response);               //  message = "you have registered.";             //}           } catch (sqlexception ex) {         //  message = "you have failed registered. please try again.";          //   ex.printstacktrace();         } {             if (conn != null) {                 // closes database connection                 try {                     conn.close();                 } catch (sqlexception ex) {                     // ex.printstacktrace();                     //silent                     //message="you have failed log in";                      getservletcontext().getrequestdispatcher("/failedmsg.jsp").include(request, response);                 }             }                 rs.close();             ps.close();             conn.close();         }}  } 

look @ sql string first:

    string sql1 ="update registration set emailaddress = ? ((firstname = ? && lastname= ? && dateofbirth= ?) || (phoneno= ? && address= ?))" ; 

in above string have 6 question marks (placeholders). setting 5 of them , indeed in wrong way. doing set firstname emailaddress, lastname firstname , on. first placeholder(?) emailaddress have follows:

    statement1.setstring(1, emailaddress);     statement1.setstring(2, firstname);     statement1.setstring(3, lastname);      statement1.setstring(4, dateofbirth);     statement1.setstring(5, phoneno);     statement1.setstring(6, address); 

can reason cannot update correctly? might getting exception. should rad console.


Comments