vendredi 17 avril 2015

I Have a DBhelper like below, when I run it error" no such as table ..... ". can u help me? There are wrong with my DBhelper?

There are wrong with my DBhelper below??:`

static final int DATABASE_VERSION = 1; static final String DATABASE_CREATE_TABLE_GAMBAR = "create table Tb_gambar (Id_gambar varchar primary key default(5) not null," +"Gambar BLOB not null,Id_kata varchar default(5) not null);";



static final String DATABASE_CREATE_TABLE_KATA =
"create table Tb_kata (Id_kata varchar primary key default(5) not null,"
+"Kata varchar default(60) not null,Id_katagori varchar default(5) not null);";

static final String DATABASE_CREATE_TABLE_KATEGORI =
"create table Tb_kategori (Id_kategori varchar primary key default(5) not null,"
+"Kategori varchar default(60) not null);";

static final String DATABASE_CREATE_TABLE_SOAL =
"create table Tb_soal (Id_soal integer primary key autoincrement,"
+"Soal varchar default(10) not null, Jawaban varchar default(10) not null, Type_soal varchar default(10) not null);";


static final String TAG = "OPERASI DATABASE";
static final String DATABASE_NAME = "Kamuskolok.db";

final Context context;

DatabaseHelper DBHelper;
SQLiteDatabase db;

public DBhelper(Context ctx)
{
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}




private static class DatabaseHelper extends SQLiteOpenHelper
{
DatabaseHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db)
{
try {
db.execSQL(DATABASE_CREATE_TABLE_GAMBAR);
db.execSQL(DATABASE_CREATE_TABLE_KATA);
db.execSQL(DATABASE_CREATE_TABLE_KATEGORI);
db.execSQL(DATABASE_CREATE_TABLE_SOAL);

} catch (SQLException e) {
e.printStackTrace();
}
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS Tb_kata");
db.execSQL("DROP TABLE IF EXISTS Tb_gambar");
db.execSQL("DROP TABLE IF EXISTS Tb_kategori");
db.execSQL("DROP TABLE IF EXISTS Tb_soal");
onCreate(db);
}
}

//---opens the database---
public DBhelper open() throws SQLException
{
db = DBHelper.getWritableDatabase();
return this;
}

//---closes the database---
public void close()
{
DBHelper.close();
}


}`


Aucun commentaire:

Enregistrer un commentaire