Reputation: 1954
I just got started with learning Android's SQLite. So I'm trying to inspect each of the methods and classes used.
public static final String DB_NAME = "myDB";
public static final String DB_TABLE = "myTable";
public static final int DB_VERSION = 1;
public static final String LNAME = "LNAME";
public static final String FNAME = "FNAME";
public static final String GENDER = "GENDER";
public static final String COURSE = "COURSE";
public class DBHelper extends SQLiteOpenHelper{
public DBHelper (Context aContext){
super(aContext,DB_NAME,null,DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL("CREATE TABLE " + DB_TABLE + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, LNAME TEXT, FNAME TEXT, GENDER TEXT, COURSE TEXT) " );
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
sqLiteDatabase.execSQL( "DROP TABLE IF EXIST " + DB_NAME );
}
}
public long Employee(String aLastName, String aFirstName, String aGender, String aCourse ){
open(); //opens the database
ContentValues cv = new ContentValues(); //creates instance of ContentValues class to store values
cv.put(LNAME,aLastName); // put(key,value) method is used to assign the parameters to its destination column in the database
cv.put(FNAME,aFirstName); //put(key,value)
cv.put(GENDER,aGender);
cv.put(COURSE,aCourse);
return myDatabase.insert(DB_TABLE,null,cv);
}
Does key
in put(key,value)
have to match the exact column name in the database?
From what I read the ContentValues
class is used to store data to the database.
I'd appreciate any explanation.
Thanks.
Upvotes: 3
Views: 6785
Reputation: 38595
Yes, key
is the column name in the database, and value
is the value to store in that column.
Upvotes: 3