title: android studio and sqlite check if username already exists
body: <p>I don't know how to avoid repeated aadhar value. please help me anyone, it is very useful for my college project. i stored my data in sqlite database, i need, if we enter exists value means show alert msg like "this value already exists" and exit the page. </p>
  
  <p>if anyone tell me how to modify my coding and give me some relevant coding. </p>
  
  <p><strong>Votingpage.java</strong></p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_votingpage);
          myDb = new DatabaseHelper(this);
  
          emailview = findViewById(R.id.emailview);
          edtaadhar1 = findViewById(R.id.edtaadhar1);
          btnlogout = findViewById(R.id.btnlogout);
          btnadd = findViewById(R.id.btnadd);
          radioGroup = findViewById(R.id.radioGroup);
  
          AddData();
  
  
          FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
          FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
          emailview.setText(firebaseUser.getEmail());
  
          btnlogout.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent intent = new Intent(Votingpage.this,MainActivity.class);
                  startActivity(intent);
              }
          });
      }
  
          private void AddData() {
              btnadd.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  if (edtaadhar1.getText().toString().trim().length() &lt;= 0) {
                      Toast.makeText(Votingpage.this, "Please enter aadhar no", Toast.LENGTH_SHORT).show();
                  }else {
  
  
                      int radioid = radioGroup.getCheckedRadioButtonId();
  
                      radioButton = findViewById(radioid);
  
                      boolean isInserted = myDb.insertData(radioButton.getText().toString(),edtaadhar1.getText().toString());
                      if (isInserted = true)
                          Toast.makeText(Votingpage.this, "Thanks for giving your vote", Toast.LENGTH_SHORT).show();
  
                      else
                          Toast.makeText(Votingpage.this, "data not inserted", Toast.LENGTH_SHORT).show();
  
  
                  }
  
              }
          });
      }
  
      public void check_button(View v){
          int radioid = radioGroup.getCheckedRadioButtonId();
  
          radioButton = findViewById(radioid);
      }
  }  
  
  
  </code></pre>
  
  <p><strong>DatabaseHelper.java</strong></p>
  
  <pre><code>public class DatabaseHelper extends SQLiteOpenHelper {
      public static final String DATABASE_NAME = "Vote.db";
      public static final String TABLE_NAME = "voter_table";
      public static final String COL_1 = "ID";
      public static final String COL_2 = "PARTY";
      public static final String COL_3 = "AADHAR";
  
  
      public DatabaseHelper(Context context) {
          super(context, DATABASE_NAME, null, 1);
      }
  
      @Override
      public void onCreate(SQLiteDatabase db) {
          db.execSQL("create table " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AUTOINCREMENT,PARTY TEXT,AADHAR INTEGER)");
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
          db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
          onCreate(db);
      }
  
  
      public boolean insertData(String party,String aadhar) {
          SQLiteDatabase db = this.getWritableDatabase();
          ContentValues contentValues = new ContentValues();
          contentValues.put(COL_2, party);
          contentValues.put(COL_3, aadhar);
  
          long result = db.insert(TABLE_NAME, null, contentValues);
          if (result == -1)
              return false;
          else
              return true;
      }
  
  }
  </code></pre>
  
  <pre><code>
  </code></pre>