我有错误//没有这样的表:Pbook(代码1)
在我的代码中
private static final String TABLE_NAME = "Pbook";
private static final String _ID = "_id";
private static final String NAME = "name";
private static final String ADDRESS = "address";
private static final String NUMBER = "number";
private static final String HUMAN = "human";
private static final String CREATE_TABLE =
"CREATE TABLE IF NOT EXIST " + TABLE_NAME + " (" +
_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
NAME + " TEXT," +
ADDRESS + " TEXT," +
NUMBER + " TEXT," +
HUMAN + " TEXT)";
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE);
}
public void insert(String name, String address, String number, String human){
SQLiteDatabase db = getWritableDatabase();
db.execSQL("insert into " + TABLE_NAME +
" (name, address, number, human) values" +
"('" + name +
"','" + address +
"','" + number +
"','" + human +"');" );
db.close();
}
当我使用insert()时会产生错误,没有这样的表:(代码1)
当然,我是db,并使用getWritableDatabase();
为什么会出错?
答案 0 :(得分:1)
这是错误的错误。它应该是CREATE TABLE IF NOT EXISTS 而不是CREATE TABLE IF NOT EXIST
private static final String CREATE_TABLE =
"CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (" +
_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
NAME + " TEXT," +
ADDRESS + " TEXT," +
NUMBER + " TEXT," +
HUMAN + " TEXT)";
卸载并重新安装您的应用程序,一切都会好的。
答案 1 :(得分:0)
String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_NAME + "("
+ KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"
+ KEY_NUM + " TEXT, "+ KEY_MAIL + " TEXT, "+ KEY_ADDR +" TEXT, " + HUMAN+ " TEXT " + ")";
db.execSQL(CREATE_CONTACTS_TABLE);
希望这会有所帮助.....