android SQLite register won't save data

AhmedEssam

I'm trying to make simple android SQLite register but when i try to save data the app crash

Database code:

Image

public class RegistrationDB extends SQLiteOpenHelper {

    private static final int DATABASE_VERSION = 1;
    private static final String DATABASE_NAME = "registration.db";
    private static final String TABLE_NAME = "profile";
    private static final String COLUMN_ID = "id";
    private static final String COLUMN_EMAIL = "email";
    private static final String COLUMN_USERNAME = "username";
    private static final String COLUMN_PASSWORD = "password";


    private static final String CREATE_TABLE =
            "CREATE TABLE " + TABLE_NAME + " (" +
                    COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                    COLUMN_USERNAME + " TEXT, "+
                    COLUMN_EMAIL + " TEXT, " +
                    COLUMN_PASSWORD + " TEXT, " + ")";

    private String DROP_TAPLE = "DROP TABLE IF EXISTS " + TABLE_NAME;

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

    }


    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL(CREATE_TABLE);

    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
        sqLiteDatabase.execSQL(DROP_TAPLE);
        onCreate(sqLiteDatabase);

    }

    public long addUser(String email, String username, String password) {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();

        values.put(COLUMN_EMAIL, email); // Email
        values.put(COLUMN_USERNAME, username); // username
        values.put(COLUMN_PASSWORD, password); // password

        // Inserting Row
//        long id = db.insert(TABLE_NAME, null, values);
        db.insert(TABLE_NAME, null, values);
        db.close(); // Closing database connection
        return 0;
    }

}

I'm sorry but I get error when I try to type code here that's why I use image

Trupti Nasit

I think there is problem in your query of create table:

COLUMN_PASSWORD + " TEXT, " + ")";

there should not be a comma "," after TEXT if its the end of the query. Remove that comma. Try if it works.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related