I create a Class named MSqliteHelper to help me use the SQlite in android project
public class MSqliteHelper extends SQLiteOpenHelper{
private static final String DATABASE_NAME = "userData"; //dataBaseName
private static final int DATABASE_VERSION = 1;
private SQLiteDatabase db;
public MSqliteHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
db = this.getWritableDatabase();
}
and I create the table like this
@Override
public void onCreate(SQLiteDatabase db) {
String DATABASE_CREATE_TABLE =
"create table userData ("
+ "HTTPorS TEXT,"
+ "IPHostName TEXT,"
+ "port TEXT,"
+ "userName TEXT,"
+ "password TEXT,"
+ "saveOption TEXT"
+ ");";
db.execSQL(DATABASE_CREATE_TABLE);
}
and I can use this method to add whole row data
public long create(String HTTPorS, String IPHostName, String port, String userName, String password, String saveOption) {
ContentValues args = new ContentValues();
args.put("HTTPorS", HTTPorS);
args.put("IPHostName", IPHostName);
args.put("port", port);
args.put("userName", userName);
args.put("password", password);
args.put("saveOption", saveOption);
return db.insert("userData", null, args);
}
and i have a method to remove whole row data at index like this
public int delete(long rowId) {
return db.delete("userData",
"_ID=" + rowId,
null
);
}
but every times I call this delete method, the app crashed
and the wrong message is like this—–
E/AndroidRuntime(2976): android.database.sqlite.SQLiteException: no such column: _ID: , while compiling: DELETE FROM userData WHERE _ID=2
where did i do wrong ?
thanks for your help!
You have to create the table with _id in it. For example