开发者

Android: Adding new rows into a SQLite database

开发者 https://www.devze.com 2023-01-30 14:49 出处:网络
I am trying to add a new row inside an existing SQLite database, but for some reason it doesn\'t seem to do it. I\'ve created this method to insert the row into the table:

I am trying to add a new row inside an existing SQLite database, but for some reason it doesn't seem to do it. I've created this method to insert the row into the table:

开发者_如何转开发
public void insertToTable(ArrayList<String> courseAttributes, ArrayList<String> attributeValues){
  ContentValues cv = new ContentValues();
  for (int i = 0 ; i < courseAttributes.size() ; i++){
     cv.put(courseAttributes.get(i), attributeValues.get(i));
  }
  coursesDataBase.insert("courses", null, cv);
}

where courseAttributes is an arraylist of all the columns in the table, attributeValues is an arraylist of the corresponding values for the row I am trying to add, coursesDataBase is the SQLiteDatabase and "courses" is the name of the table in this database. I don't get any errors when I run it on the debugger, however it does not store the new row in the database. I call the method from another class, in between the following open and close methods:

public void openDataBase() throws SQLException{

 //Open the database
    String myPath = DB_PATH + DB_NAME;
 coursesDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);

}

and

@Override
public synchronized void close() {

     if(coursesDataBase != null)
      coursesDataBase.close();

     super.close();

}
0

精彩评论

暂无评论...
验证码 换一张
取 消