마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

데이터베이스 rawquery관련질문 ㅠㅠ

0 추천
public class DBAdapter extends SQLiteOpenHelper {
    private static final String DB_NAME = "mygrade.db";
    private static final int VERSION = 1;
    public static Cursor cursor;
    private static final String ID = "_id";
    private static final String SUBJECT = "subject";
    private static final String SEMESTER = "semester";
    private static final String GRADE = "grade";
    private static final String ISU = "isu";
    private static final String CREDIT = "credit";
    private static final String TABLE_NAME = "mygrades";
    public static int count;
    private static final String CREATE_TABLE =
        "CREATE TABLE " + TABLE_NAME + " (" +
        ID + " integer primary key autoincrement, " +
                SUBJECT + " text not null, " +
                SEMESTER + " text not null," + CREDIT +" text not null, " + GRADE +" text not null, " + ISU + " text not null );";

    private SQLiteDatabase db;

    public DBAdapter(Context context) {
        super(context, DB_NAME, null, VERSION);
        db = this.getWritableDatabase();
    }

    @Override
    public synchronized void close() {
        db.close();
        super.close();
    }

    @Override
    protected void finalize() throws Throwable {
        close();
        super.finalize();
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
        onCreate(db);
    }

//     create
    public boolean insertInfo(String subject, String semester, String grade, String isu, String credit) {
        ContentValues cv = new ContentValues();
        cv.put(SUBJECT, subject);
        cv.put(SEMESTER, semester);
        cv.put(GRADE,grade);
        cv.put(ISU, isu);
        cv.put(CREDIT, credit);
        return db.insert(TABLE_NAME, null, cv) != -1;
    }


    public Cursor QueryData(){

        cursor = db.rawQuery("select subject from mygrades " ,null);
        if(cursor !=null){
            count = cursor.getCount();
            for(int i = 0; i<count; i++){
                cursor.moveToNext();
            }
        }
        return  cursor;


    }

위에게 dbadapter 액티비티이고

 public void itemView(){
        mDb = new DBAdapter(this);
        mDb.cursor = mDb.QueryData();

        if(mDb.cursor!= null ){
            String[] columns = {"subject"};


            int[] name = {R.id.subjectname};
            SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.line, mDb.cursor, columns, name);

        listView2.setAdapter(adapter);

밑에게 메인액티비티인데요

 

위에 dbadapter 액티비티에서 rawquery메소드에서 "select * from mygrades"를 입력하면 잘 출력되는데 반해,

"select subject from mygrades"를 입력하면 계속 오류가 나네요 ㅠㅠ 무엇이 문제일까요??

개수이 (260 포인트) 님이 2015년 11월 12일 질문

1개의 답변

+1 추천
어떤 오류인지 exception 이 나올 겁니다. 로그를 올리세요
aucd29 (218,390 포인트) 님이 2015년 11월 13일 답변
...