我是android的新手并制作了一个我需要从服务器数据库中获取数据的应用程序。我能够以简单的方式获取数据,但是,我想获取关于列" KEY_SCORE"的所有数据。在desc顺序和设置testID = 1等。我尝试了很多,但没有成功。请有人帮助我。
这是我的数据库代码
package com.education.dBase;
import java.util.ArrayList;
import android.content.ContentValues;
import android.database.Cursor;
import android.util.Log;
import com.education.mobiCoachAllen.NotificationListItem;
public class ToppersTable extends BaseTable {
public static final String KEY_ID = "_id";
public static final String KEY_USERID = "userid";
public static final String KEY_SCORE = "score";
public static final String KEY_COUNTER = "timecounter";
public static final String KEY_NAME = "fullname";
public static final String TABLE_NAME2 = "quiz_toppers";
public static final String TABLE_CREATE_TOPPERS = "CREATE TABLE "
+ TABLE_NAME2 + " (" + KEY_ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_USERID + " TEXT, "
+ KEY_COUNTER + " TEXT, " + KEY_NAME + " TEXT, " + KEY_SCORE
+ " TEXT);";
String getTableName() {
return TABLE_NAME2;
}
public ToppersTable(DbHelper dbHelper) {
super(dbHelper);
}
public long insert(String userid, String counter, String name, String score) {
log("insert answer : " + score);
long rowid_attribute;
ContentValues values = new ContentValues();
values.put(KEY_USERID, userid);
values.put(KEY_COUNTER, counter);
values.put(KEY_NAME, name);
values.put(KEY_SCORE, score);
rowid_attribute = super.insert(values);
return rowid_attribute;
}
public ArrayList<NotificationListItem> getAllList(
ArrayList<NotificationListItem> privateArrayList) {
privateArrayList.clear();
Cursor cursor = null;
db = dbHelper.getReadableDatabase();
cursor = db.query(getTableName(), null, null, null, null, null, null);
log("getAlllist() cursor : " + cursor.getCount());
if (cursor != null) {
log("getAlllist() cursor not null ");
// log(" getAllAlarms() cursor size =" + cursor.getCount());
int index = 0;
cursor.moveToFirst();
while (index < cursor.getCount()) {
NotificationListItem item = new NotificationListItem();
int idIndex = cursor.getColumnIndex(ToppersTable.KEY_USERID);
int scoreIndex = cursor.getColumnIndex(ToppersTable.KEY_SCORE);
int idCounter = cursor.getColumnIndex(ToppersTable.KEY_COUNTER);
int nameIndex = cursor.getColumnIndex(ToppersTable.KEY_NAME);
item.name = cursor.getString(nameIndex);
item.testID = cursor.getString(idIndex);
item.cmark = cursor.getString(scoreIndex);
item.time = cursor.getString(idCounter);
index++;
privateArrayList.add(item);
cursor.moveToNext();
}
log(" query(): cursor closing");
cursor.close();
db.close();
db = null;
}
return privateArrayList;
}
public void deleteitem(int Id) {
// TODO Auto-generated method stub
db = dbHelper.getWritableDatabase();
String WHERE = KEY_ID + "=" + Id;
db.delete(getTableName(), WHERE, null);
db.close();
}
public void deleteDateitem(String date) {
// TODO Auto-generated method stub
db = dbHelper.getWritableDatabase();
/*
* String WHERE = KEY_NAME + "=" + date; db.delete(getTableName(),
* WHERE, null);
*/
db.delete(getTableName(), KEY_SCORE + "=?", new String[] { date });
Log.e("Record Deleted", "" + date);
db.close();
}
public void deleteAll() {
db = dbHelper.getWritableDatabase();
// db.delete(TABLE_NAME2, null, null);
// db.execSQL("delete * from"+ TABLE_NAME);
db.execSQL("delete from " + TABLE_NAME2);
db.close();
}
@SuppressWarnings("null")
public String getSinlgeEntry(String qid) {
db = dbHelper.getReadableDatabase();
Cursor cursor = null;
cursor = db.query(TABLE_NAME2, null, "qid =?", new String[] { qid },
null, null, null);
if (cursor != null) {
if (cursor.getCount() < 1) // UserName Not Exist
{
cursor.close();
return "NOT EXIST";
}
} else {
return "NOT EXIST";
}
cursor.moveToFirst();
String userId = cursor.getString(cursor.getColumnIndex(KEY_SCORE));
cursor.close();
db.close();
return userId;
}
}