Im trying to use sqlite as my database for my app. At first i have create a table for the user when they sign up. But when i create the second table for the booking, it says no such table Below is my code
public class DBhelper extends SQLiteOpenHelper {
public static final String DBNAME="database.db";
public DBhelper(@Nullable Context context) {
super(context,"database.db", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table users(username TEXT primary key, password TEXT )");
db.execSQL("create table booking(serviceID INTEGER primary key, name TEXT,email TEXT,phone TEXT )");
}
@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
db.execSQL("drop table if exists users");
db.execSQL("drop table if exists booking");
onCreate(db);
}
public Boolean insertData(String username, String password){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("username",username);
values.put("password", password);
long result = db.insert("users",null,values);
if(result==-1)return false;
else
return true;
}
public void addNewBooking( int serviceID, String name,String notes, String phone, String email) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
// on below line we are passing all values
// along with its key and value pair.
values.put("serviceID", serviceID);
values.put("name", name);
values.put("notes", notes);
values.put("phone", phone);
values.put("email", email);
// after adding all values we are passing
// content values to our table.
db.insert("booking", null, values);
// at last we are closing our
// database after adding database.
}
public Boolean checkusername(String username){
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery("select * from users where username = ?", new String[] {username});
if(cursor.getCount()>0){
return true;
}else
return false;
}
public Boolean checkuserpass(String username, String password){
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery("select * from users where username =? and password =?", new String[] {username,password});
if(cursor.getCount()>0){
return true;
}else
return false;
}
}
below is the error shown
E/SQLiteLog: (1) table booking has no column named serviceID in "INSERT INTO booking(serviceID,name,email,notes,phone) VALUES (?,?,?,?,?)"
E/SQLiteDatabase: Error inserting serviceID=0 name=name email=em notes=no phone=12
android.database.sqlite.SQLiteException: table booking has no column named serviceID (code 1 SQLITE_ERROR): , while compiling: INSERT INTO booking(serviceID,name,email,notes,phone) VALUES (?,?,?,?,?)