Actually I am working on this for the last 3 or 4 weeks but have not able to resolve it. I am working on Sqlite Database in android in which I have used a date picker control in my activity Once a user sets a date then i'll stored the date into the string and then sends it to the database it is working fine but when i tried to retrieve the date on the basis of date set on date picker control then it doesn't give me the desired output it show the only a line which is opening a database on my catlog.
Database Class
//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;
}
Activity Class Code
//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();
}
Thanks for any help in advance!!!!!!