우선 코드는 다음과 같습니다.
package exam.ProductList;
import android.app.*;
import android.content.*;
import android.database.*;
import android.database.sqlite.*;
import android.os.*;
import android.widget.*;
public class ProductList extends Activity {
ProductDBHelper helper;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
helper=new ProductDBHelper(this);
Cursor cursor;
SQLiteDatabase db=helper.getWritableDatabase();
cursor=db.rawQuery("select * from product", null);
startManagingCursor(cursor);
SimpleCursorAdapter adapter=null;
adapter=new SimpleCursorAdapter(this,android.R.layout.simple_list_item_2,cursor,new String[]{"title","con"},
new int[]{android.R.id.text1,android.R.id.text2});
ListView list=(ListView)findViewById(R.id.list);
list.setAdapter(adapter);
}
}
class ProductDBHelper extends SQLiteOpenHelper{
public ProductDBHelper(Context context){
super(context,"Product.db",null,1);
}
public void onCreate(SQLiteDatabase db){
db.execSQL("create table product(_id integer primary key autoincrement, "+"title text, con text);");
db.execSQL("insert into product values(null,'기본기','가장낮은단계입니다');");
db.execSQL("insert into product values(null,'초급2','초급단곕니다');");
db.execSQL("insert into product values(null,'중급2','중급임니다');");
db.execSQL("insert into product values(null,'고급2','최상위단계');");
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
db.execSQL("drop table if exists product;");
onCreate(db);
}
}
SQLiteOpenHelper를 상속받은 객체로 만들었는데요
첨부된 사진과 같이 Product.db안에 product테이블은 저런 상태입니다.
그러고 나서 위에 코드를 실행하면 이전 product지워지고 새로 insert된것들로 떠야 하는거아닌가요? 계속 사진에나온 테이블로 뜨네요 ㅜ



