i am newbie in android, trying to add data in SqLite Database. i am adding name and number in database but i am getting syntax error. i checked many sites but i hardly found any syntax error. if anyone can give any kind of help, i will be thankful. here is my code :
@Override
public void onCreate(SQLiteDatabase db)
{
String tablecreate = "create table " + tableName + " ( " + ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + NAME + " TEXT,"
+ NUMBER + " TEXT )";
db.execSQL(tablecreate);
}
public void addContact(String name, String num) {
SQLiteDatabase database = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(NAME, name);
cv.put(NUMBER, num);
database.insert(tableName, null, cv);
database.close();
}
and here is what log cat says :
06-24 15:09:04.930: E/SQLiteLog(1426): (1) near "number": syntax error
06-24 15:09:04.980: E/SQLiteDatabase(1426): Error inserting phone number=1234567890 name=mom
06-24 15:09:04.980: E/SQLiteDatabase(1426): android.database.sqlite.SQLiteException: near "number": syntax error (code 1): , while compiling: INSERT INTO CONTACTS_TABLE(phone number,name) VALUES (?,?)
06-24 15:09:04.980: E/SQLiteDatabase(1426): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
06-24 15:09:04.980: E/SQLiteDatabase(1426): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
06-24 15:09:04.980: E/SQLiteDatabase(1426): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
06-24 15:09:04.980: E/SQLiteDatabase(1426): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
06-24 15:09:04.980: E/SQLiteDatabase(1426): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
Aucun commentaire:
Enregistrer un commentaire