Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //package com.khirulnizam.placeofinterest;
- import android.content.Context;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteOpenHelper;
- public class MyDB extends SQLiteOpenHelper {
- final protected static String DATABASE_NAME="POI";//define DB name
- public MyDB(Context context) {
- super(context, DATABASE_NAME, null,1);
- }
- @Override
- public void onCreate(SQLiteDatabase db) {//1st time install auto create DB
- //here is the database definition
- //or some data to insert
- //CREATE TABLE pbentry ((id, entri, makna, contoh, englishproverb, englishmeaning, sumber, kategori);
- db.execSQL("CREATE TABLE lokasi (" +
- "namalokasi TEXT," +
- "latitude REAL," +
- "longitude REAL);");
- //data entry
- //Eg: db.execSQL("INSERT INTO orang (nama, jantina, negeri) VALUES(‘Khirulnizam', ‘lelaki‘, ‘Negeri Sembilan’);");
- db.execSQL("INSERT INTO lokasi (namalokasi, latitude, longitude) " +
- "values ('KUIS', '2.890484', '101.788470')");
- db.execSQL("INSERT INTO lokasi (namalokasi, latitude, longitude) " +
- "values ('Masjid Shah Alam', '3.078622', '101.520718')");
- db.execSQL("INSERT INTO lokasi (namalokasi, latitude, longitude) " +
- "values ('Zoo Negara', '3.209096', '101.758233')");
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- if (newVersion > oldVersion){//renew DB if DB upgraded to new version
- //do something if database is updated
- db.execSQL("DROP TABLE IF EXISTS pbentry");
- onCreate(db);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment