mardi 27 janvier 2015

android sqlite create table error

I am trying to create a table in sqlite db, but getting the error saying



java.lang.RuntimeException: Unable to start activity ComponentInfo{com.learnsocial.testingdatabase/com.learnsocial.testingdatabase.MainActivity}: android.database.sqlite.SQLiteException: near "Index": syntax error (code 1): , while compiling: create table hierarchie (Index int, Robot_Num int, Nom text, C_0 text, C_1 text, C_2 text, C_3 text, C_4 text)


And the code snippet is



public class DbHelper extends SQLiteOpenHelper{

static final String TAG = "DbHelper";
public static final String DB_NAME = "wikwio_idao.db";
public static final int DB_VERSION = 1;

//hierarchie table columns
public static final String TABLE = "hierarchie";
public static final String H_INDEX = "Index";
public static final String H_ROBOT = "Robot_Num";
public static final String H_NOM = "Nom";
public static final String H_C0 = "C_0";
public static final String H_C1 = "C_1";
public static final String H_C2 = "C_2";
public static final String H_C3 = "C_3";
public static final String H_C4 = "C_4";



public DbHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
// TODO Auto-generated constructor stub
}


@Override
public void onCreate(SQLiteDatabase db) {

String sql = "create table " + TABLE + " (" + H_INDEX + " int, "
+ H_ROBOT + " int, " + H_NOM + " text, " + H_C0 + " text, " + H_C1 + " text, " + H_C2 + " text, "
+ H_C3 + " text, " + H_C4 + " text)";
db.execSQL(sql);
Log.d(TAG,"oncreate-database");


}


@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

db.execSQL("drop table if exists "+ TABLE);
onCreate(db);
}

}


I gave correct space only, but i am not able to find the problem..


Aucun commentaire:

Enregistrer un commentaire