vendredi 25 septembre 2015

sqlite database not create in my file explore android

hello friends i wnat ot create sqlite databse by query so i write below code for that

public class DBHandler extends SQLiteOpenHelper {

// All Static variables
// Database Version
private static final int DATABASE_VERSION = 1;

// Database Name
private static final String DATABASE_NAME = "abc";

// Contacts table name
private static final String TABLE_CONTACTS = "user";

// Contacts Table Columns names
private static final String KEY_ID = "id";
private static final String KEY_EMAIL = "email";
private static final String KEY_NAME = "pin";
private static final String KEY_PH_NO = "key";

public DBHandler(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
    System.out.println("Call");
}

// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
    String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "("
            + KEY_ID + " INTEGER PRIMARY KEY," + KEY_EMAIL + " TEXT,"+ KEY_NAME + " TEXT,"
            + KEY_PH_NO + " TEXT" + ")";
    db.execSQL(CREATE_CONTACTS_TABLE);
}

// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)   {
    // Drop older table if existed
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS);

    // Create tables again
    onCreate(db);
}
}

Main.java

public class AndroidSQLiteTutorialActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    DatabaseHandler db = new DatabaseHandler(this);
      }
    }

When i run above code it will not create database in my file explore option of my emulator any idea how can i solve? your all suggestions are applicable

Aucun commentaire:

Enregistrer un commentaire