Database insert not working on Android
Hi I'm doing an Android application and I have a database. I'm able to do queries but the inserts don't seem to be working. I have a table named profile with the fields "id", "name" and "original".
This is the method:
public void addProfile(String name)
{
myDataBase.rawQuery("INSERT INTO profile(name, original) values('"+name+"', '0')", null);
}
And what I'm doing:
DataBaseHelper myDbHelper = new DataBaseHelper(activity);
try {
myDbHelper.createDataBase();
} catch (IOException ioe) {
throw new Error("Unable to create database");
}
try {
myDbHelper.openDataBase();
} catch (SQLException sqle) {
throw sqle;
}
for(Profile p : profiles){
myDbHelper.addProfile(p.getName());
System.out.println("Commiting profile "+ p.getName());
In LogCat it correctly appears "Commiting profile test".
I'm opening the database with:
myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
I've searched everywhere for the erro and I can't seem to find it. Is it because I have an "id" instead of "_id" on the table? Wouldn't that only affect the SELECTs? In my Selects I use select id as 开发者_高级运维_id but in insert I don't know how to do it.
It is not allowed to use rawQuery to insert data. You should use execSQL
精彩评论