2012-03-19 56 views
0

当我运行我的代码, 无法启动活动ComponentInfo:android.database.sqlite.SQLiteException:近“/”:语法错误..的Android SQLite的异常接近“/”

为什么它不工作? 三江源所有提前.. 这里是我的助手类

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 

} 
+0

检查此'KEY_CONTENT2 =“AC /非AC” – idiottiger 2012-03-19 08:35:51

+0

我不太确定,但我认为它不允许使用“空格”和“特殊字符”像列名中的“/”... – drulabs 2012-03-19 08:36:11

+0

请参阅这个帖子http://stackoverflow.com/questions/3373234/what-sqlite-column-name-can-be-cannot-be – ccheneson 2012-03-19 08:36:48

回答

1

SQLite中的表和列名称中不能有/,并且您试图调用列Ac/non ac

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

+0

谢谢你的反馈。 – 2012-03-19 09:00:42

0

尝试重命名KEY_CONTENT2的东西“/”在它没有。我认为'/'是不可接受的名称。并从名称中删除所有空格。

0

或用其unicode替换它。 U + 002F

+0

它工作正常...非常感谢... – 2012-03-19 08:47:29