I try to insert multiple data to sqlite in android but I can't. I want to create and insert like the code bolow, please help me.
here is my bad code,
package com.pepakbahasajawa.database;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class PepakDatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "pepakdb";
private static final int DATABASE_VERSION = 1;
//Pembuatan Database
private static final String DATABASE_CREATE_1 = "create table pepak (_id integer primary key autoincrement, "
+ "name text not null);";
private static final String DATABASE_CREATE_2 = "create table category (_id integer primary key autoincrement, "
+ "id_pepak integer(11) not null, cat_name varchar(255) not null);";
private static final String DATABASE_CREATE_3 = "create table subcategory (_id integer primary key autoincrement, "
+ "id_category integer(11) not null, subcat_name varchar(255) not null);";
private static final String DATABASE_CREATE_4 = "create table posts (_id integer primary key autoincrement, "
+ "id_subcategory integer(11) not null, post_name_1 varchar(255) not null, post_name_2 varchar(255));";
public PepakDatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase database) {
// TODO Auto-generated method stub
database.execSQL(DATABASE_CREATE_1);
database.execSQL(DATABASE_CREATE_2);
database.execSQL(DATABASE_CREATE_3);
database.execSQL(DATABASE_CREATE_4);
String sql = "INSERT INTO pepak (name), category (name), subcategory (id_category)," +
"(subcat_name), posts (id_subcategory), (post_name_1), (post_name_2)" +
"VALUES (Kawruh Rupa), VALUES (1), VALUES (Tetawuhan), VALUES (1), VALUES (Arane Kembang), VALUES (1)," +
"VALUES (Kembang aren - Arane Dangu), VALUES (Bunga Aren - Disebut Dangu)";
Log.v("simapn oke", sql);
database.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase database, int oldVersion,
int newVersion) {
Log.w(PepakDatabaseHelper.class.getName(),
"Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
database.execSQL("DROP TABLE IF EXISTS pepak");
database.execSQL("DROP TABLE IF EXISTS category");
database.execSQL("DROP TABLE IF EXISTS subcategory");
database.execSQL("DROP TABLE IF EXISTS posts");
onCreate(database);
}
}
Please help. Thanks