0

我正在尝试从我的 android 应用程序中的 Sqlite 数据库返回数据(存储的锻炼信息:名称、周期、用户在特定日期播放的燃烧卡路里),但出现异常:

 android.database.sqlite.SQLiteException: near ",": syntax error: , while compiling:    SELECT Name, Period, Burned_Calories FROM Exercise WHERE Date = Tuesday, 8/May/2012

为什么会发生此异常,我该如何解决?请帮我 ..

这是我的代码:

DBAdapter db = new DBAdapter(this);
db.open();
String selected_date= date_btn.getText().toString();

 Cursor c = db.getExerciseInfo(selected_date );

 if (c.moveToFirst())
 {
  do 
  {
    Toast.makeText(this ,"Name: "+ c.getString(0) + "\n" + "Period:" +c.getFloat(1)+ "\n" + " burned cals:" +c.getFloat(2)+ "\n" ,Toast.LENGTH_LONG).show();
  }
    while (c.moveToNext());

   }
  db.close();

这是我在 DBAdapter 类中的方法

public Cursor getExerciseInfo(String  date) throws SQLException
        {
       Cursor  C_excer = db.query(EXERCISE_TABLE_NAME, new String[]       {KEY_NAME,KEY_PERIOD,KEY_BURNEDCALS},KEY_DATE +" = " + date, null, null, null, null);
           if (C_excer != null) {
      C_excer.moveToFirst();
             }
        return C_excer;
             }
4

3 回答 3

0

尝试用引号括起你的日期:''。像这样:

 Cursor  C_excer = db.query(EXERCISE_TABLE_NAME, new String[] { KEY_NAME,KEY_PERIOD, KEY_BURNEDCALS}, KEY_DATE + " = '" + date + "'", null, null, null, null);
于 2012-05-08T16:25:25.003 回答
0

从您发布的内容中很难判断,但是您的 where 子句看起来很可疑:

WHERE Date = Tuesday, 8/May/2012 -- boom!

尝试更改为:

WHERE Date = 'Tuesday, 8/May/2012'
于 2012-05-08T16:25:34.613 回答
0

不是专家,但也许你需要一些报价:

android.database.sqlite.SQLiteException: near ",": syntax error: , while compiling:    SELECT Name, Period, Burned_Calories FROM Exercise WHERE Date = "Tuesday, 8/May/2012"
于 2012-05-08T16:29:16.297 回答