Create Insert statement - Android Database

Android examples for Database:SQL Insert

Description

Create Insert statement

Demo Code


//package com.java2s;

import android.database.sqlite.SQLiteDatabase;

import android.util.Log;

public class Main {
    private static final String LOG_TAG = "BoardDatabaseOpenHelper";

    /**//  w  w  w .j a va 2 s .  co m
     * Creates the initial data for the app
     * @param db
     */
    private static void createSeedData(SQLiteDatabase db) {
        Log.d(LOG_TAG, "Inserting seed data");

        StringBuilder sql = new StringBuilder();
        sql.append("INSERT INTO GameEngine (Id, Name) VALUES (1, 'Checkers');\n");

        // Checkers Engine Row 1
        sql.append("INSERT INTO GameEngineState (Engine,Id,Row,Column,State,Chip) VALUES (1,0,0,0,4,1);\n");
        sql.append("INSERT INTO GameEngineState (Engine,Id,Row,Column,State,Chip) VALUES (1,1,0,1,2,2);\n");

        String[] queries = sql.toString().split("\n");
        for (int i = 0; i < queries.length; i++) {
            db.execSQL(queries[i]);
        }
    }
}

Related Tutorials