안드로이드 개발 질문/답변
(글 수 45,052)
public class WP_listActivity extends Activity{ /** Called when the activity is first created. */ static final String DEVELOP = "Creat By ybn100 "; static final String DB="whitepage.db";//DB이름 static final String WP_TABLE = "wp_table"; // 주소록 DB 이름 static final String GP_TABLE = "gp_table"; // 그룹 DB 이름 static final String RC_TABLE = "rc_table"; // 최근통화내역 DB 이름 static final int DB_VERSION=1;//DB버전
static final String CREATE_WP_TABLE ="create table wp_table(_id integer PRIMARY KEY AUTOINCREMENT,wp_name text not null," + "phone integer not null,phone2 integer,phone3 integer,address text, email text, shortnum integer, gp_id integer not null, " + "photo text, birth text, rc_time text,wp_ring text, randomcall boolean default 'true');";
static final String CREATE_GP_TABLE ="create table gp_table(_id integer PRIMARY KEY AUTOINCREMENT,gp_name text not null,gp_ring text);";
static final String CREATE_RC_TABLE ="create table rc_table(_id integer PRIMARY KEY AUTOINCREMENT,gp_id integer not null," + "call_time text not null,call_cost integer not null)"; // 테이블 삭제 SQL static final String DROP_WP_TABLE = "drop table wp_table;"; static final String DROP_GP_TABLE = "drop table gp_table;"; static final String DROP_RC_TABLE = "drop table rc_table;"; SQLiteDatabase mDb;
private static class DBConn extends SQLiteOpenHelper { public DBConn(Context c) { // 데이터베이스의 파일 이름과 버전을 지정 super(c, DB, null, DB_VERSION); } // 데이터베이스를 새로 만든 다음 호출 public void onCreate(SQLiteDatabase db) { // 내부에 테이블 만들기 db.execSQL(CREATE_WP_TABLE); db.execSQL(CREATE_GP_TABLE); db.execSQL(CREATE_RC_TABLE); }
// 존재하는 데이터베이스로 정의하고있는 버전이 다를 때 public void onUpgrade(SQLiteDatabase db,int oldVersion, int newVersion) { // 여기에서는 테이블을 삭제하고 새로 작성함 // 일반적으로 테이블의 데이터 변환을 수행 db.execSQL(DROP_WP_TABLE); db.execSQL(DROP_GP_TABLE); db.execSQL(DROP_RC_TABLE); onCreate(db); } }
// 작업이 포그라운드 된 시간에 데이터를 표시 protected void onResume() { super.onResume();
// 데이터베이스를 쓰기 위한 열 DBConn conn = new DBConn(getApplicationContext()); try { mDb = conn.getWritableDatabase(); } catch (SQLiteException e) { // 디스크 전체에서 데이터를 쓸 수없는 경우 mDb = conn.getReadableDatabase(); } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.wp_list); ArrayAdapter<CharSequence> Adapter; Adapter = ArrayAdapter.createFromResource(this, R.array.wp_list,android.R.layout.simple_list_item_1); ListView list2 = (ListView)findViewById(R.id.list); list2.setAdapter(Adapter); Cursor cursor = mDb.rawQuery("select * from wp_table",null); startManagingCursor(cursor); } }
3개의 액티비티를 인텐드로 연결한 프로그램중 세번쨰 페이지입니다.
두번쨰 페이지에서 입력을 받고 세번쨰 페이지에서 조회를 하려하는데요
디비에 셀렉트 쿼리만 날려도 오류가 발생합니다.
한번 확인해주세요.. 필요하시면 나머지 부분도 올려드릴께요.