So I have pre defined sql database where I have a method that gets only 4 data and inserts it into the database. And I have another method that only gets 1 data and inserts it into the database but all I get is another row in the database.
Here's my code
`public class DBHelper extends SQLiteOpenHelper {
public static final String USERS_TABLE = "USERS_TABLE";
public static final String COLUMN_ID = "ID";
public static final String COLUMN_NAME = "NAME";
public static final String COLUMN_USERNAME = "USERNAME";
public static final String COLUMN_PASSWORD = "PASSWORD";
public static final String COLUMN_AGE = "AGE";
public static final String COLUMN_CONTACT = "CONTACT";
public static final String COLUMN_DIARY = "DIARY";
public DBHelper(Context context) {
super(context, "Login.db", null, 1);
}
@Override
public void onCreate(SQLiteDatabase MyDataBase) {
String createTableStatement = "CREATE TABLE " + USERS_TABLE +
" (" + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
COLUMN_NAME + " TEXT, " +
COLUMN_USERNAME + " TEXT, " +
COLUMN_PASSWORD + " TEXT, " +
COLUMN_AGE + " TEXT, " +
COLUMN_CONTACT + " TEXT, " +
COLUMN_DIARY + " TEXT)";
MyDataBase.execSQL(createTableStatement);
}
public Boolean insertData (int id, String name, String username, String password, String age){ SQLiteDatabase MyDataBase = this.getWritableDatabase(); ContentValues contentValues = new ContentValues();
contentValues.put(COLUMN_NAME, name);
contentValues.put(COLUMN_USERNAME, username);
contentValues.put(COLUMN_PASSWORD, password);
contentValues.put(COLUMN_AGE, age);
long result = MyDataBase.insert(USERS_TABLE,null,contentValues);
if (result == -1) {
return false;
}
else {
return true;
}
}
public Boolean insertContact (String contact){
SQLiteDatabase MyDataBase = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COLUMN_CONTACT, contact);
long result = MyDataBase.insert("users",null,contentValues);
if (result == -1) return false;
else
return true;
}`