I am creating an android application using Eclipse. I want to ask on how to create a database using SQLite. The database will only have 3 tables which is user_id, user_name, and user_password.
2 Answers
- Formulate
CREATEstatements for your tables. (a) on desktop create a SQLite db and then push the directory to emulator. Use SQLite command line to execute these statements, or
(b) connect to android shell then you will get SQLite shell. or
(c) in your android activity, fire SQL command (as mentioned by
user522751)
2 Comments
You can try SQLiteOpenHelper, here is what i did in a demo app few weeks ago.. import static com.kevin.fastcard.utils.ColumnConstants.; import static com.kevin.fastcard.utils.DBConstants.;
public class DBHelper extends SQLiteOpenHelper { public DBHelper(Context context) { super(context, DB_NAME, null, DB_VERSION); }
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE " + TBL_NAME + "(" + _ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT," + QUESTION + " TEXT,"
+ ANSWER + " TEXT," + CATEGORY + " TEXT," + CREATE_TIME
+ " TEXT," +TIME_IN_MILLIS+" INTEGER"+ ");");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.delete(TBL_NAME, null, null);
}
}
I'm new to android, hope that can help you..