dimanche 7 février 2016

Sqlite insertion issue

i am getting an errors in my android program need help i new to android

2-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteLog: (1) table table3 has no column named name 02-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteDatabase: Error inserting name=alinf password=asifjiejf username=aksdjfiej 02-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteDatabase: android.database.sqlite.SQLiteException: table table3 has no column named name (code 1): , while compiling: INSERT INTO table3(name,password,username) VALUES (?,?,?) 02-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteDatabase: at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) 02-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteDatabase: at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887) 02-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteDatabase: at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498) 02-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteDatabase: at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 02-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteDatabase: at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58) 02-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteDatabase: at android.database.sqlite.SQLiteStatement.(SQLiteStatement.java:31) 02-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteDatabase: at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469) 02-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteDatabase: at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1341) 02-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteDatabase: at com.example.ks.doit.sqlite_database.insertData(sqlite_database.java:34) 02-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteDatabase: at com.example.ks.doit.Insertion$1.onClick(Insertion.java:54) 02-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteDatabase: at android.view.View.performClick(View.java:5198) 02-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteDatabase: at android.view.View$PerformClick.run(View.java:21147) 02-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteDatabase: at android.os.Handler.handleCallback(Handler.java:739) 02-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteDatabase: at android.os.Handler.dispatchMessage(Handler.java:95) 02-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteDatabase: at android.os.Looper.loop(Looper.java:148) 02-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteDatabase: at android.app.ActivityThread.main(ActivityThread.java:5417) 02-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteDatabase: at java.lang.reflect.Method.invoke(Native Method) 02-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteDatabase: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 02-07 23:41:03.052 7613-7613/com.example.ks.doit E/SQLiteDatabase: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 02-07 23:41:03.130 7613-7638/com.example.ks.doit W/EGL_emulation: eglSurfaceAttrib not implemented 02-07 23:41:03.130 7613-7638/com.example.ks.doit W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xabe82e60, error=EGL_SUCCESS 02-07 23:41:06.575 7613-7638/com.example.ks.doit E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab84f230 02-07 23:48:30.318 7613-7619/com.example.ks.doit W/art: Suspending all threads took: 9.032ms

//this is my Sqlite class code
public boolean insertData(String name, String userName, String password)
    {
        SQLiteDatabase mydatabase = helper.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(Helper.NAME,name);
        contentValues.put(Helper.USERNAME,userName);
        contentValues.put(Helper.PASSWORD, password);
        long result = mydatabase.insert(Helper.TABLE_NAME,null,contentValues);
        if (result <= 0)
        {
            return false;
        }
        else
        {
            return true;
        }
    }

class Helper extends SQLiteOpenHelper
    {

        //database information
        private static final String DATABASE_NAME="mydatabase3";
        private static final int DTABASE_VERSION=11;
        //table information
        private static final String TABLE_NAME="table3";
        private static final String NAME="name";
        private static final String USERNAME="username";
        private static final String PASSWORD="password";

        Context context;
        public Helper(Context context) {
            super(context,DATABASE_NAME, null, DTABASE_VERSION);
            this.context = context;
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            String CREATE_TABLE=
                    "CREATE TABLE"+
                            " "+Helper.TABLE_NAME+" "+
                            "("
                            +Helper.NAME+"TEXT,"
                            +Helper.USERNAME+"TEXT,"
                            +Helper.PASSWORD+"TEXT);";
            db.execSQL(CREATE_TABLE);
            Toast.makeText(context, "database create", Toast.LENGTH_LONG).show();
        }

Aucun commentaire:

Enregistrer un commentaire