我在Android中开发了一个基于测验的应用程序。现在,当我试图以降低顺序排列高分时,问题就出现了。我收到错误invalid LIMIT clauses:score DESC
。我在这里发布了我的数据库类和我试图以降低顺序获取高分的类。请帮我解决这个错误。
DBAdapter.java
public long addscore(String name, int score)
{
ContentValues values = new ContentValues();
values.put(KEY_name, name);
values.put(KEY_score, score);
return db.insert(DATABASE_TABLE1, null, values);
}
public Cursor getScore() throws SQLException
{
String order = KEY_score + " DESC ";
/*return db.query(DATABASE_TABLE1, new String[] {KEY_scoreid, KEY_name,
KEY_score}, null, null, null, null, order);*/
Cursor mCursor = db.query(true, DATABASE_TABLE1, new String[] {
KEY_scoreid, KEY_name,KEY_score },null, null,null,null, null,order);
if (mCursor != null)
{
mCursor.moveToFirst();
}
return mCursor;
}
Highscore.java
try
{
db1=new DBAdapter(this);
db1.open();
c=db1.getScore();
n1=c.getString(1);
s1=c.getInt(2);
n2=c.getString(1);
s2=c.getInt(2);
n3=c.getString(1);
s3=c.getInt(2);
n4=c.getString(1);
s4=c.getInt(2);
n5=c.getString(1);
s5=c.getInt(2);
name1.setText(n1);
score1.setText(Integer.toString(s1));
name2.setText(n2);
score2.setText(Integer.toString(s2));
name3.setText(n3);
score3.setText(Integer.toString(s3));
name4.setText(n4);
score4.setText(Integer.toString(s4));
name5.setText(n5);
score5.setText(Integer.toString(s5));
}
catch(Exception ex)
{
Toast.makeText(getBaseContext(), ex.getMessage(), Toast.LENGTH_SHORT).show();
}
我需要你的帮助,请帮忙!
先谢谢。
答案 0 :(得分:0)
查询应该是那样的
Cursor mCursor = db.query(true, DATABASE_TABLE1, new String[] {
KEY_scoreid, KEY_name,KEY_score },null, null,null,null,KEY_score + " DESC",null);
答案 1 :(得分:0)
试试如下:
Cursor mCursor =db.query(DATABASE_TABLE1, new String[] {KEY_scoreid,KEY_name,KEY_score}, null, null, null, null, KEY_score + " DESC");
<强>编辑:强>
if (cur.getCount() > 0) { if (cur.moveToFirst()) { do { id1 = cur.getInt(0); name = cur.getString(1); Contacts contact_list = new Contacts(id1, name); contact.add(contact_list); } while (cur.moveToNext()); } cur.deactivate(); cur.close(); cdb.close(); }
Contact
如下所示:
public class Contacts
{
private int Id;
private String NAME;
public int getId()
{
return Id;
}
public void setId(int id)
{
this.Id = id;
}
public String getNAME()
{
return NAME;
}
public void setNAME(String name)
{
NAME = name;
}
public Contacts(int id, String name)
{
super();
this.Id = id;
NAME = name;
}
}