init Database by creating two tables - Android Database

Android examples for Database:Table Create

Description

init Database by creating two tables

Demo Code


//package com.book2s;

import android.content.Context;

import android.database.sqlite.SQLiteDatabase;

public class Main {
    public static void initDatabase(Context context) {
        SQLiteDatabase db = context.openOrCreateDatabase("data.db",
                context.MODE_PRIVATE, null);
        db.execSQL("CREATE TABLE IF NOT EXISTS Projects (id VARCHAR PRIMARY KEY, projectName VARCHAR, position  VARCHAR, desc VARCHAR,createTime DATETIME,modifyTime DATETIME)");
        db.execSQL("CREATE TABLE IF NOT EXISTS ProjectItems (id VARCHAR PRIMARY KEY,pid VARCHAR, itemName VARCHAR, score VARCHAR, score_type VARCHAR,photo VARCHAR,desc VARCHAR)");
        db.close();//from  www.  ja v  a 2  s .  c o m
    }
}

Related Tutorials