Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement