title: Get first row data if exist in SQLite
body: <p>I am writing an app in which i need to fetch first row data if exist in SQLite database table, I have written code to store data into database, but now i want to fetch first row data from database into TextView(s).</p>
  
  <p><strong>HelperClass:-</strong></p>
  
  <pre><code>    // Select Data
      public String[] SelectData(String strOperatorID) {
          // TODO Auto-generated method stub
  
           try {
              String arrData[] = null;    
  
               SQLiteDatabase db;
               db = this.getReadableDatabase(); // Read Data
  
               Cursor cursor = db.query(TABLE_NAME, new String[] { "*" }, 
                          "OperatorID=?",
                          new String[] { String.valueOf(strOperatorID) }, null, null, null, null);
  
                  if(cursor != null)
                  {
                      if (cursor.moveToFirst()) {
                          arrData = new String[cursor.getColumnCount()];
  
                          arrData[0] = cursor.getString(0); // DeviceID
                          arrData[1] = cursor.getString(1); // EmailID
                          arrData[2] = cursor.getString(2); // Event
                          arrData[3] = cursor.getString(3); // Operator
                          arrData[4] = cursor.getString(4); // EventOperator
                      }
                  }
  
                  cursor.close();
                  db.close();
                  return arrData;
  
           } catch (Exception e) {
              return null;
           }
      }   
  </code></pre>
  
  <p>As you can see, i have written code to get data on the basis of OperatorID=? but now i just need to fetch first row data into textviews.</p>
  
  <p>So let me know what are the changes i need to commit in my above code, to get first row data if exist, otherwise so toast does not exist.</p>
  
  <p><strong>LoginActivity.java:</strong></p>
  
  <pre><code>               // Save Data
           long saveStatus = myDb.InsertData(
              txtDeviceID.getText().toString(),
              txtEmailID.getText().toString(),
              txtEvent.getText().toString(),
              txtOperative.getText().toString(),
              txtEventOperator.getText().toString()
          );
  </code></pre>
  
  <p>using above code i am storing data into database, and in a same way i want to fetch data from database and want to show whenever user comes to LoginActivity.java, no matter after closing app properly...</p>
  
  <p><strong>Updated:-</strong></p>
  
  <pre><code>public class LoginActivity extends Activity  {
      .................
  
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
          setContentView(R.layout.activity_login);
  
          btnLogout = (Button) findViewById(R.id.btnLogout);
          btnCamera = (Button) findViewById(R.id.btnCamera);
          btnGallery = (Button) findViewById(R.id.btnGallery);
  
              txtDeviceID = (TextView) findViewById(R.id.txtDeviceID);
              txtEmailID = (TextView) findViewById(R.id.txtEmailID);      
              txtEvent = (TextView) findViewById(R.id.txtEvent);  
              txtOperative = (TextView) findViewById(R.id.txtOperative);
              txtEventOperator = (TextView) findViewById(R.id.txtEventOperator);
  
               Intent intent = getIntent();
               deviceID = intent.getStringExtra("deviceID");
               emailID = intent.getStringExtra("emailID");
               event = intent.getStringExtra("name"); 
               operative = intent.getStringExtra("firstName");
  
               txtDeviceID.setText(deviceID);
               txtEmailID.setText(emailID);
               txtEvent.setText(event);
               txtOperative.setText(operative);
               txtEventOperator.setText(event + "  " + operative);
  
               strEvent = txtEvent.getText().toString();
               strOperative = txtOperative.getText().toString();
  
                  // Dialog
                  final AlertDialog.Builder adb = new AlertDialog.Builder(this);
                  AlertDialog ad = adb.create();
  
                  // new Class DB
                  final myDBClass myDb = new myDBClass(this);
  
                  // Save Data
                  long saveStatus = myDb.InsertData(
                              txtDeviceID.getText().toString(),
                              txtEmailID.getText().toString(),
                              txtEvent.getText().toString(),
                              txtOperative.getText().toString(),
                              txtEventOperator.getText().toString()
                              );
  
                  if(saveStatus &lt;=  0)
                  {
                    ad.setMessage("Error!! ");
                    ad.show();
                    return;
                  }   
  
                  // Show Data
                  String arrData[] = myDb.SelectData();
                  if(arrData != null)
                  {
                      txtDeviceID.setText(arrData[1]);
                      txtEmailID.setText(arrData[2]);
                      txtEvent.setText(arrData[3]);
                      txtOperative.setText(arrData[4]);
                      txtEventOperator.setText(arrData[5]);
                  }  
  
   if(txtEvent.getText().toString().equals("") &amp;&amp; txtOperative.getText().toString().equals(""))
                  {
                      Intent intentCall = new Intent(LoginActivity.this, LicenseListActivity.class);
                      startActivity(intentCall);
                  }
            }
  </code></pre>