title: How to check if username and password is in the database SQLite?
body: <p>Trying to make a basic login activity but I'm still quite new to all this.
  I've got a username and password in the database (and am going to add functionality to add more users soon). What I want is when they type in their username and password it checks if the pair exist in the database, if so return true, else, return false.</p>
  
  <p>So this is in my DB connector</p>
  
  <pre><code>    public boolean checkLogin(String username, String password) {
      SQLiteDatabase db = md.getWritableDatabase();
  
      String s;
      Cursor c = db.rawQuery("SELECT * FROM MyTable WHERE " + username + " =? AND" + password + " =?", null);
  
      if(c.getCount() &lt;= 0) {
          c.close();
          db.close();
          return false;
      } else {
          c.close();
          db.close();
          return true;
      }
  }
  </code></pre>
  
  <p>This is where the code is being called - in my main activity</p>
  
  <pre><code>        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 i = new Intent(getApplicationContext(), DBTest.class);
                  startActivity(i);
              } else {
                  Toast.makeText(getApplicationContext(), "Invalid login", Toast.LENGTH_SHORT).show();
              }
  
          }
      });
  </code></pre>
  
  <p>Here is the error. From what I know it's a syntax error but I'm not too sure how to go about amending it</p>
  
  <pre><code>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 * FROM History WHERE Admin =? AND1234 =?
                                                                                        at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                                                                                        at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
                                                                                        at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
                                                                                        at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
                                                                                        at android.database.sqlite.SQLiteProgram.&lt;init&gt;(SQLiteProgram.java:58)
                                                                                        at android.database.sqlite.SQLiteQuery.&lt;init&gt;(SQLiteQuery.java:37)
                                                                                        at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
                                                                                        at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)
                                                                                        at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1255)
                                                                                        at com.example.c1641195.testproject.MyDBConnector.checkLogin(MyDBConnector.java:66)
                                                                                        at com.example.c1641195.testproject.MainActivity$1.onClick(MainActivity.java:30)
                                                                                        at android.view.View.performClick(View.java:5198)
                                                                                        at android.view.View$PerformClick.run(View.java:21147)
                                                                                        at android.os.Handler.handleCallback(Handler.java:739)
                                                                                        at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                        at android.os.Looper.loop(Looper.java:148)
                                                                                        at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  </code></pre>