android - How to check if username and password is in the database SQLite? -


trying make basic login activity i'm still quite new this. i've got username , password in database (and going add functionality add more users soon). want when type in username , password checks if pair exist in database, if return true, else, return false.

so in db connector

    public boolean checklogin(string username, string password) {     sqlitedatabase db = md.getwritabledatabase();      string s;     cursor c = db.rawquery("select * mytable " + username + " =? and" + password + " =?", null);      if(c.getcount() <= 0) {         c.close();         db.close();         return false;     } else {         c.close();         db.close();         return true;     } } 

this code being called - in main activity

        btnsubmit.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             boolean validuser = mydb.checklogin(username.gettext().tostring(), password.gettext().tostring());              if(validuser == true) {                 intent = new intent(getapplicationcontext(), dbtest.class);                 startactivity(i);             } else {                 toast.maketext(getapplicationcontext(), "invalid login", toast.length_short).show();             }          }     }); 

here error. know it's syntax error i'm not sure how go amending it

04-05 19:08:46.536 11313-11313/com.example.c1641195.testproject e/sqlitelog: (1) near "and1234": syntax error 04-05 19:08:46.536 11313-11313/com.example.c1641195.testproject d/androidruntime: shutting down vm 04-05 19:08:46.536 11313-11313/com.example.c1641195.testproject e/androidruntime: fatal exception: main process: com.example.c1641195.testproject, pid: 11313 android.database.sqlite.sqliteexception: near "and1234": syntax error (code 1): , while compiling: select * history admin =? and1234 =? @ android.database.sqlite.sqliteconnection.nativepreparestatement(native method) @ android.database.sqlite.sqliteconnection.acquirepreparedstatement(sqliteconnection.java:887) @ android.database.sqlite.sqliteconnection.prepare(sqliteconnection.java:498) @ android.database.sqlite.sqlitesession.prepare(sqlitesession.java:588) @ android.database.sqlite.sqliteprogram.(sqliteprogram.java:58) @ android.database.sqlite.sqlitequery.(sqlitequery.java:37) @ android.database.sqlite.sqlitedirectcursordriver.query(sqlitedirectcursordriver.java:44) @ android.database.sqlite.sqlitedatabase.rawquerywithfactory(sqlitedatabase.java:1316) @ android.database.sqlite.sqlitedatabase.rawquery(sqlitedatabase.java:1255) @ com.example.c1641195.testproject.mydbconnector.checklogin(mydbconnector.java:66) @ com.example.c1641195.testproject.mainactivity$1.onclick(mainactivity.java:30) @ android.view.view.performclick(view.java:5198) @ android.view.view$performclick.run(view.java:21147) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:5417) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:726) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:616)

there syntax error on line " =? and" + password combines and , returned password. try " =? , " + password leaves space after and


Comments