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"를 입력하면 계속 오류가 나네요 ㅠㅠ 무엇이 문제일까요??