svs
svs

Reputation: 397

android SQLite exception near "/"

When I run my code, Unable to start activity ComponentInfo: android.database.sqlite.SQLiteException: near "/": syntax error..

Why it doesn't work? Thankyou all in advance.. Here is my helper class

public class Helper extends SQLiteOpenHelper{

public static final String MYDATABASE_TABLE = "Restaurant";
public static final String KEY_ID = "_id";
public static final String KEY_CONTENT1 = "Restaurant name";
public static final String KEY_CONTENT2 = "Ac/non ac";
public static final String KEY_CONTENT3 = "Total chairs";
public static final String KEY_CONTENT4 = "Reserved chairs";
public static final String KEY_CONTENT5 = "Date";
public static final String KEY_CONTENT6 = "fromTime"; 
public static final String KEY_CONTENT7 = "toTime"; 
public static final String KEY_CONTENT8 = "Name";
public static final String KEY_CONTENT9 = "Contact Number";
public static final String KEY_CONTENT10 = "Table id";


private static final String SCRIPT_CREATE_DATABASE =
      "create table " + MYDATABASE_TABLE + " ("
      + KEY_ID + " integer primary key autoincrement, "
      + KEY_CONTENT1 + " text not null, "
      + KEY_CONTENT2 + " text not null, "
      + KEY_CONTENT3 + " integer not null, "
      + KEY_CONTENT4 + " integer not null, "
      + KEY_CONTENT5 + " text not null, "
      + KEY_CONTENT6 + " text not null, "
      + KEY_CONTENT7 + " text not null, "
      + KEY_CONTENT8 + " text not null, "
      + KEY_CONTENT9 + " text not null, "
      + KEY_CONTENT10 + " text not null) ";


public Helper(Context context, String name, CursorFactory factory,
        int version) {
    super(context, name, factory, version);
    // TODO Auto-generated constructor stub
}

@Override
public void onCreate(SQLiteDatabase db) {
    // TODO Auto-generated method stub
    db.execSQL(SCRIPT_CREATE_DATABASE);

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub

}

Upvotes: 0

Views: 443

Answers (3)

Joachim Isaksson
Joachim Isaksson

Reputation: 180977

Table and column names in SQLite cannot have / in them, and you're trying to call a column Ac/non ac.

The support for special characters in table and column names in SQLite is a bit sketchy overall, so I'd also recommend using replacing your spaces in the column names with _. The alternative is to enclose them in quotes, but that may/may not work depending on SQLite version.

Upvotes: 1

Rajdeep Dua
Rajdeep Dua

Reputation: 11230

Or replace it with its unicode. U+002F

Upvotes: 0

Alexander
Alexander

Reputation: 48272

Try renaming KEY_CONTENT2 to something not having '/' in it. I think '/'s are unacceptable in the names. And also remove all the spaces from the names.

Upvotes: 0

Related Questions