简体   繁体   中英

Error in Creating an Sqlite database

I created a method to save data into an sqlite database , but it seems i have a problem using it.

    public void saveDataInDB(double latitude, double longitude) {


        SQLiteDatabase db = openOrCreateDatabase(DB_NAME, MODE_PRIVATE, null);


        db.execSQL("CREATE TABLE IF NOT EXISTS "
                + TABLE_NAME
                + " (CurrentDate VARCHAR(20), Lat DOUBLE, Lng DOUBLE, Alt DOUBLE, Speed DOUBLE);");


        db.execSQL("INSERT INTO " + TABLE_NAME + " VALUES('" + latitude + "', '" + longitude + "');");


        Cursor c = db.rawQuery("SELECT * FROM " + TABLE_NAME, null);
        c.moveToLast();


        db.close();
        db.getPath();

    }

This method worked fine when i used it in a location application to save the location , when i tried to re-use it in another application to save another values it didn't work. It produces an error "MODE_PRIVATE can't resolve to a variable.I have changed the parameters to fit to my new application , i only having one parameter instead of longitude and latitude.

Any help , all i want is to save a value called "sum" into the database.

If you are going to save only one value, use shared preferences instead of using database. But, if you are going to use database it would much better to use SQLiteOpenHelper . you can check it in this tutorial http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/

Also concerning your code, i'm not sure where are you using this code but you have to use Context.MODE_PRIVATE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM