android SQLite异常在“/”附近

时间:2012-03-19 08:33:44

标签: android sql sqlite

当我运行我的代码时,  无法启动活动ComponentInfo:android.database.sqlite.SQLiteException:near“/”:syntax error ..

为什么它不起作用? 谢谢大家.. 这是我的帮助班

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

}

3 个答案:

答案 0 :(得分:1)

SQLite中的表名和列名不能包含/,并且您尝试调用列Ac/non ac

SQLite中对表名和列名中的特殊字符的支持总体上有点粗略,因此我还建议使用_替换列名中的空格。另一种方法是将它们用引号括起来,但这取决于SQLite版本可能/可能不起作用。

答案 1 :(得分:0)

尝试将KEY_CONTENT2重命名为其中没有“/”的内容。我认为'/'在名字中是不可接受的。并且还从名称中删除所有空格。

答案 2 :(得分:0)

或者用它的unicode替换它。 U + 002F