2011-05-10 3 views
0

내 응용 프로그램에서 사용자의 edittext를 통해 int 값을 가져 와서 데이터베이스에 저장하는 설정 탭이 있습니다. 이제 사용자가 설정을 변경하려고 할 때 이전 설정이 데이터베이스에서 업데이트되어야합니다. 어떻게 데이터베이스 코드를 작성합니까?android 데이터베이스의 값을 업데이트

DatabaseHelper dha = new DatabaseHelper(this); 
      SQLiteDatabase db = dha.getWritableDatabase(); 
      Log.d("","Done with database Sqlite"); 
      ContentValues cv = new ContentValues(); 
      EditText editText2 = (EditText) this.findViewById(R.id.editText1); 
      setTime = editText2.getText().toString(); 
      Log.d(setTime, "This is the setTime value"); 
      cv.put(DatabaseHelper.TIME, setTime); 
      db.insert("finalP", DatabaseHelper.TIME, cv); 
      db.close(); 
+0

그럴 게요 그래 ... 내 말은 내가 밖으로 시도하지 않은 아래의 제안. 나는 뭔가의 한가운데에있다. –

답변

4

당신은 같이해야합니다 : : 아래

은 DB에 값을 저장하려면 코드입니다

// Create content values that contains the name of the column you want to update and the value you want to assign to it 
ContentValues cv = new ContentValues(); 
cv.put("my_column", "5"); 

String where = "my_column=?"; // The where clause to identify which columns to update. 
String[] value = { "2" }; // The value for the where clause. 

// Update the database (all columns in TABLE_NAME where my_column has a value of 2 will be changed to 5) 
db.update(TABLE_NAME, cv, where, value); 
관련 문제