title: Android sqlite how to check if a record exists
body: <p>I would like to check whether a record exists or not. </p>
  
  <p>Here is what I've tried:</p>
  
  <p><strong>MainActivity.class</strong></p>
  
  <pre><code>    public void onTextChanged(CharSequence s, int start, int before, int count) {
  
          System.out.println("Ontext changed " + new String(s.toString()));
          strDocumentFrom = s.toString();         
  
          if(s.toString().isEmpty()){
  
          } else {
  
               try{
                   strTransactionDate = dbHelper.getTransactionDateByDocumentNumber(strDocumentFrom);
                   //strTotalAmount = dbHelper.getTotalAmountByDocumentNumber(strDocumentFrom);
                   //strVan = dbHelper.getVanByDocumentNumber(strDocumentFrom);
  
  
                   //etTransactionDate.setText(strTransactionDate);
                   //etTotalAmount.setText(strTotalAmount);
                   //Log.d("Van", "" + strVan);
                   //etVan.setText(strVan);
  
               } catch (SQLiteException e) {
                   e.printStackTrace();
                   Toast.makeText(ReceivingStocksHeader.this, 
                           "Document number does not exist.", Toast.LENGTH_SHORT).show();
               }
  
          }
  </code></pre>
  
  <p><strong>DBHelper.class</strong></p>
  
  <pre><code>            // TODO DISPLAYING RECORDS TO TRANSRCVHEADER
          public String getTransactionDateByDocumentNumber(String strDocumentNumber){
              String[] columns = new String[]{KEY_TRANSACTIONDATE};
  
              Cursor c = myDataBase.query(TBL_INTRANS, 
                      columns, null, 
                      null, null, null, null, null);
  
              if(c != null){
                  c.moveToFirst();
                  String date = c.getString(0);
                  return date;
              } else {
                  Log.d("Error", "No record exists");
              }
  
  
              return null;
          }
  </code></pre>
  
  <p>But it doesn't get it to the catch block to display the toast. </p>
  
  <p>What am I doing wrong in here? </p>