mercredi 9 décembre 2015

How to fix android.database.sqlite.SQLiteException: near "-": syntax error (code 1): , while compiling: -

I am creating an android application that consists f the database storage and here i need to store the float values then retrieve the float values from database to the edit text fields.When i am executing the application it says like " android.database.sqlite.SQLiteException: near "Beforefuseoffsets": syntax error (code 1): , while compiling: Beforefuseoffsets" .I know it was the syntax error but where is that error i didn't find that can any one tell me how to pass through this. This is my database code:

package com.lakshman.androidfiles;

    import java.io.File;

    import android.content.ContentValues;
    import android.content.Context;
    import android.database.Cursor;
    import android.database.SQLException;
    import android.database.sqlite.SQLiteDatabase;
    import android.view.View;

    public class LoginDataBaseAdapter 
    {
            //Database name
            static final String DATABASE_NAME = "MilanloginRegistration.db";
            static final int DATABASE_VERSION = 1;
            public static final int NAME_COLUMN = 1;
            public static final String ID ="ID";
            // TODO: Create public field for each column in your table.
            // SQL Statement to create a new database.
            public static final String OFFSETS_B_FUSE = "Beforefuseoffsets";


            public static final String OFFSET_VALUE="offsetvalues";

            public static DataBaseHelper database_helper;
            public Context context_db;


            static final String OFFSETS_BC_FUSE ="CREATE TABLE IF NOT EXISTS "+OFFSETS_B_FUSE+" ("+ID+" integer primary key autoincrement, "+OFFSET_VALUE+" INT)";


            static float[] offset_entry;
            // Variable to hold the database instance
            public static  SQLiteDatabase db;
            // Context of the application using the database.
            private static Context context;
            // Database open/upgrade helper
            private static DataBaseHelper dbHelper;
            public  LoginDataBaseAdapter(Context _context) 
            {
                context = _context;
                dbHelper = new DataBaseHelper(context, DATABASE_NAME, null, DATABASE_VERSION);
            }
            public  LoginDataBaseAdapter open() throws SQLException 
            {
                db = dbHelper.getWritableDatabase();
                return this;
            }
            public void close() 
            {
                db.close();
            }

            public  SQLiteDatabase getDatabaseInstance()
            {
                return db;
            }
            public LoginDataBaseAdapter opentoRead() throws android.database.SQLException{

                dbHelper = new DataBaseHelper(context, DATABASE_NAME, null, DATABASE_VERSION);
                db = dbHelper.getReadableDatabase();
                return this;
            }
            public LoginDataBaseAdapter opentoWrite() throws android.database.SQLException{

                dbHelper = new DataBaseHelper(context, DATABASE_NAME, null, DATABASE_VERSION);
                db = dbHelper.getWritableDatabase();
                return this;
            }

            public void Close(){
                dbHelper.close();
            }



            public static void insert_offset_Entry(float values)
            {
               ContentValues newValues = new ContentValues();

                newValues.put(OFFSET_VALUE,values);
                database_helper = new DataBaseHelper(context,DATABASE_NAME,null,DataBaseHelper.VERSION);
                db = database_helper.getWritableDatabase();
                db.insert(OFFSETS_B_FUSE,null,newValues);
            }

            public LoginDataBaseAdapter db_to_write() {
                database_helper = new DataBaseHelper(context,DATABASE_NAME,null,DataBaseHelper.VERSION);
                db = database_helper.getWritableDatabase();
                return this;
            }






            /*public void Display(View v){
                Cursor c = db.rawQuery("select * from MilanloginRegistration", null);

                c.moveToFirst();
                do{
                    String username = c.getFloat(c.getColumnIndex(""));
                    String password = c.getString(1);


                }while(c.moveToNext());
            }*/
        }

Aucun commentaire:

Enregistrer un commentaire