create new Table if it not exists - Android Database

Android examples for Database:Table Create

Description

create new Table if it not exists

Demo Code


//package com.java2s;

import android.database.sqlite.SQLiteDatabase;

import android.util.Log;

public class Main {
    public static SQLiteDatabase db;
    public static String tablename = "cowlist";

    public static void createCowListTable() {
        try {/*from ww  w  .  j a v  a 2s .co  m*/
            db.execSQL("create table if not exists " + tablename + "("
                    + " _id integer PRIMARY KEY autoincrement, "
                    + " location text," + " number text, " + " sex text,"
                    + " birthday text);");
        } catch (Exception ext) {
            Log.d("Create detail fail", "table make fail");
        }
    }
}

Related Tutorials