Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8659719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:04:46+00:00 2026-06-12T16:04:46+00:00

I have an app tha has in a sqlite database some measures. From an

  • 0

I have an app tha has in a sqlite database some measures.

From an activity(Email Activity) the user selects which data will be sent to doctor’s email(the data of last 1/7/30 days).

enter image description here

This is the code of this activity:

import com.oikonomopo.blood.pressure.tracker.dao.BpDAO;

...

public class EmailActivity extends Activity implements OnItemSelectedListener {

    Spinner spinner;
    String[] measures = { "today", "7 days", "30 days" };

    private Calendar theStart;
    private Calendar theEnd;
    SimpleDateFormat dateFormat;
    String start;
    String end;

    //this refers to another class for the manipulate of my table
    private BpDAO dao = null;

    private Button sendEmailBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.email);

        // ////////////////////////////////////
        theEnd = Calendar.getInstance();
        theStart = (Calendar) theEnd.clone();
        dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        // //////////////////////////////////

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                EmailActivity.this, android.R.layout.simple_spinner_item,
                measures);

        sendEmailBtn = (Button) findViewById(R.id.button1);
        spinner = (Spinner) findViewById(R.id.spinner1);
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(this);

        // BpDao - refers to my table - see later
        dao = new BpDAO(this);

        // add a click listener to the button
        sendEmailBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
/////////////////////////////////////////////////////////////////////////////////////////
                Log.d("BPT", "before"); // it works untill here
                Cursor bpLastDaysList = dao.lastXdays_bp(start, end);
                Log.d("BPT", "after"); //doesn't reach the code here!!
/////////////////////////////////////////////////////////////////////////////////////////
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        dao.close();
    }

    public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
            long arg3) {
        int position = spinner.getSelectedItemPosition();
        switch (position) {

                // last day
        case 0:
            theStart.add(Calendar.DAY_OF_MONTH, -1);

            // date boundaries in TEXT format
            start = dateFormat.format(theStart.getTime());
            end = dateFormat.format(theEnd.getTime());
            //
            break;

        // last 7 days
        case 1:
            theStart.add(Calendar.DAY_OF_MONTH, -7);

            // date boundaries in TEXT format
            start = dateFormat.format(theStart.getTime());
            end = dateFormat.format(theEnd.getTime());
            //
            break;

        // last 30 days
        case 2:
            theStart.add(Calendar.DAY_OF_MONTH, -30);

            // date boundaries in TEXT format
            start = dateFormat.format(theStart.getTime());
            end = dateFormat.format(theEnd.getTime());
            //
            break;
        }
    }

}

But it gives me this logcat error:

    FATAL EXCEPTION: main
android.database.sqlite.SQLiteException: near "09": syntax error: , while compiling: SELECT DISTINCT systolic, diastolic, datetime, _id, notes, pulses FROM bp_import WHERE datetime BETWEEN 2012-10-12 09:44 AND 2012-10-12 09:44 ORDER BY datetime DESC
at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
...
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1405)
at com.oikonomopo.blood.pressure.tracker.dao.BpDAO.lastXdays_bp(BpDAO.java:76)
at com.oikonomopo.blood.pressure.tracker.EmailActivity$1.onClick(EmailActivity.java:70)

android.database.sqlite.SQLiteException: near “09”: syntax error: , while compiling: SELECT DISTINCT systolic, diastolic, datetime, _id, notes, pulses FROM bp_import WHERE datetime BETWEEN 2012-10-12 09:44 AND 2012-10-12 09:44 ORDER BY datetime DESC


The code for the function of the BpDAO class is :

    public class BpDAO {
        private DatabaseHelper_bp dbHelper;
        private SQLiteDatabase database;
        /**
         * Movie table related constants.
         */
        public final static String bp_TABLE = "bp_import";
        public final static String bp_ID = "_id";
        public final static String bp_DT = "datetime";
        public final static String bp_SYS = "systolic";
        public final static String bp_DIA = "diastolic";
        public final static String bp_PUL = "pulses";
        public final static String bp_NOT = "notes";

        public BpDAO(Context context) {
            dbHelper = new DatabaseHelper_bp(context);
            database = dbHelper.getWritableDatabase();
        }

        /**
         * \ Creates a new blood pressure measure
         * 
         * @param datetime
         * @param systolic
         * @param diastolic
         * @param pulses
         * @param notes
         * @return
         */
        public long importBP(String datetime, String systolic, String diastolic,
                String pulses, String notes) {
            ContentValues values = new ContentValues();
            values.put(bp_DT, datetime);
            values.put(bp_SYS, systolic);
            values.put(bp_DIA, diastolic);
            values.put(bp_PUL, pulses);
            values.put(bp_NOT, notes);
            return database.insert(bp_TABLE, null, values);
        }

    // this is working perfect
        /**
         * Fetch all bps sorted DESCending
         * @return
         */
        public Cursor fetchAll_bp() {
            Cursor mCursor = database.query(true, bp_TABLE, new String[] { bp_SYS,
                    bp_DIA, bp_DT, bp_ID, bp_NOT, bp_PUL }, null, null, null, null,
                    bp_DT + " DESC", null);
            if (mCursor != null) {
                mCursor.moveToFirst();
            }
            return mCursor;
        }
    // here is the problem!
        /**
         * Fetch all bps sorted DESCending by date(yyyy-mm-dd hh:mm) of last
         * X[1-7-30] days
         * @return
         */
        public Cursor lastXdays_bp(String start, String end) {
            Cursor mCursor = database.query(true, bp_TABLE, new String[] { bp_SYS,
                    bp_DIA, bp_DT, bp_ID, bp_NOT, bp_PUL }, "datetime BETWEEN "
                    + start + " AND " + end, null, null, null, bp_DT + " DESC",
                    null);
            if (mCursor != null) {
                mCursor.moveToFirst();
            }
            return mCursor;
        }
//
        public void close() {
            database.close();
        }
    }

And the code of the DatabaseHelper_bp(extends SQLiteOpenHelper) is :

    public class DatabaseHelper_bp extends SQLiteOpenHelper {

    private static final String DATABASE_NAME = "bpDB";
    private static final int DATABASE_VERSION = 1;

    // Database creation sql statement
    private static final String DATABASE_CREATE = "create table bp_import ( _id integer primary key, datetime text not null, systolic text not null, diastolic text not null, pulses text not null, notes text not null);";

    public DatabaseHelper_bp(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    // Method is called during creation of the database
    @Override
    public void onCreate(SQLiteDatabase database) {
        database.execSQL(DATABASE_CREATE);
    }

    // Method is called during an upgrade of the database,
    @Override
    public void onUpgrade(SQLiteDatabase database, int oldVersion,
            int newVersion) {
        Log.w(DatabaseHelper_bp.class.getName(),
                "Upgrading database from version " + oldVersion + " to "
                        + newVersion + ", which will destroy all old data");
        database.execSQL("DROP TABLE IF EXISTS bp_import");
        onCreate(database);
    }
}

I save the datetime as text in sqlite. (2012-10-12 09:43)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:04:47+00:00Added an answer on June 12, 2026 at 4:04 pm
    Cursor mCursor = database.query(true, bp_TABLE, new String[] { bp_SYS,
                    bp_DIA, bp_DT, bp_ID, bp_NOT, bp_PUL }, "datetime BETWEEN ?
                  AND ?" , new String[]{start,end}, null, null, bp_DT + " DESC",
                    null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have app in which I'm downloading image from web to iphone app. This
I have app which retrieve applications from registry. In 32bits Windows it works correctly.
I have app in which if there is data in local data base then
I have app which has actionbar containing 1) up button which opens side bar
We have App A as main app. Now we build from it App B
I have app in which i have recorded sound files i want that i
lets say i have app id, app secret id and user uid now i
for example: I have app A, which references library A and library B. in
Have an app that has listings - think classified ads - and each listing
my app have action bar on top of windows. Where are some buttons. Buttons

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.