0

实际上,我在过去 3 或 4 周内一直在努力解决这个问题,但还没有解决。我正在使用 android 中的 Sqlite 数据库,其中我在我的活动中使用了日期选择器控件一旦用户设置了日期,我会将日期存储到字符串中,然后将其发送到数据库,它工作正常但是当我试图根据日期选择器控件上设置的日期来检索日期,然后它没有给我所需的输出,它只显示了在我的目录日志中打开数据库的一行。

数据库类

//Table Definition with Columns
private static final String CREATE_MYCOMPANY =
    "create table company " + " (" + "_id" + " integer primary key autoincrement, "
    + "company_date" +" date);";


//Insert Method
public long create(String str) {

    ContentValues args = new ContentValues();
    args.put(KEY_COMPANY_DATE, str);

    return mDb.insert(MYCOMPANY, null,args);
}




//Method For Fetching the row on the basis of Date.//
    public Cursor fetchdate(String datr) throws SQLException, ParseException {

    Cursor mCursor =
        mDb.query(true, MYCOMPANY, new String[] {KEY_COMPANY_ID,
                KEY_COMPANY_DATE}, KEY_COMPANY_DATE /*+" BETWEEN date('2012-6-10') AND date('2012-6-14')"*/ 
                 + " = " + datr, null,
                null, null, null, null);

    if (mCursor != null) {
        mCursor.moveToFirst();
    }


    return mCursor;

}

活动类代码

//Date picker 
DatePicker  dt = (DatePicker)findViewById(R.id.datePicker1);

//Converting the Date into the string format  
String day = String.valueOf(dt.getYear())+"-" +String.valueOf(dt.getMonth() + 1)
            +"-"+String.valueOf(dt.getDayOfMonth());


//Method for displaying the rows of table on date basis
public void DisplayAllCmpData(){

        employeeTable.open();
        try{
          Cursor c = employeeTable.fetchdate("2012-6-13");
          if (c.moveToFirst())
           {
             do {
              System.out.println("bool2");
                 DisplayCmpTitle(c);
                } while (c.moveToNext());
           }
         }catch(Exception e){
        System.out.println(e);
     Toast.makeText(this,e.toString(),Toast.LENGTH_LONG).show();
           }
         employeeTable.close();
    }

//Function For Displaying the all record.//    
    public void DisplayCmpTitle(Cursor c)
    { 

    System.out.println("bool");
       Toast.makeText(this,
           "ID: " + c.getString(0) + "\n" +
           "DATE: " + c.getString(1)
           , Toast.LENGTH_LONG).show();

    }

提前感谢您的任何帮助!!!!!!!

4

1 回答 1

0
mDb.query(true, MYCOMPANY, new String[] {KEY_COMPANY_ID,
                KEY_COMPANY_DATE}, KEY_COMPANY_DATE /*+" BETWEEN date('2012-6-10') AND date('2012-6-14')"*/ 
                 + " = '" + datr+"'", null,
                null, null, null, null);
于 2012-06-13T07:11:46.127 回答