java - Prepared statement and setString -


i have problem setstring. when add % parameter in setstring, works if don't write anything. however, when remove it doesn't work. can help?

string id= user1.gettext().tostring(); string passwords = pass.gettext().tostring();   btnlogin.setonclicklistener(new view.onclicklistener() {             public void onclick(view v) {          string query = "select * table id ? , pass ? ";             try {                 if (connect != null) {                    preparedstatement statement = connect.preparestatement(query);                 statement.setstring(1, id );  //  statement.setstring(1 ,"%" + id + "%");                statement.setstring(2 ,passwords);//  statement.setstring(2 ,"%" + passwords + "%");                    r = statement.executequery();                     if (r.next()){                          intent intent = new intent();                         intent.setclass(login.this, mainactivity.class);                         startactivity(intent);                             }                      else {                         message = "error";                         info.settext(message);                     }                  } else {                     message = "error in connection sql server";                     info.settext(message);                 }               } catch (sqlexception e) {                 etat = false;                 message = "got exception!";                 system.err.println(e.getmessage());             }       }});  } 

p.s: no errors

that because sql query begging syntax.

if not want use %%, pass direct string , change query = query.

select * table id = ? , pass = ? 

but checking username , password operator terrible idea. check equals or not.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -