dimanche 8 février 2015

android.database.sqlite.SQLiteException: table X has no column named Y:

I want to create new entry in database . This is my database class:


public class DataBase {



private static final String DATABSE_NAME = "MY_DB";
private static final String DATABSE_TABLE_LOGIN = "tblLogin";
private static final int DATABASE_VERSION = 1;

public static final String DUM="DUM";
public static final String BOOKER_ID = "BookerID";
public static final String BNAME = "BName";
public static final String PASS = "Pass";
String[] Columns_Login = new String[]{DUM,BOOKER_ID,BNAME,PASS};


public static final String DATABASE_CREATE = " CREATE TABLE " + DATABSE_TABLE_LOGIN + " (" +
DUM + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
BOOKER_ID+" TEXT NOT NULL, "+
BNAME + " TEXT NOT NULL, " +
PASS + " TEXT NOT NULL) " ;


private DatabaseHelper myHelper;

private final Context mycontext;
private SQLiteDatabase myDB;


private static class DatabaseHelper extends SQLiteOpenHelper {

public DatabaseHelper(Context context) {
super(context, DATABSE_NAME, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}

@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub

db.execSQL(DATABASE_CREATE);

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS " + DATABSE_TABLE_LOGIN);
onCreate(db);
}

}

public DataBase(Context c) {
mycontext = c;
}

public DataBase open() throws SQLException {

myHelper = new DatabaseHelper(mycontext);
myDB = myHelper.getWritableDatabase();
return this;
}

public void close() throws SQLException {
myHelper.close();
}

public long createEntry(String _BID, String _BName, String _Pass) throws SQLException {
// TODO Auto-generated method stub
ContentValues cv = new ContentValues();
cv.put(BOOKER_ID, _BID);
cv.put(BNAME,_BName);
cv.put(PASS,_Pass);
return myDB.insert(DATABSE_TABLE_LOGIN, null, cv);
}

public Boolean CheckLogin(String _BID, String _Pass) throws SQLException{
Boolean Y_N =false ;
// Cursor c = myDB.rawQuery("select * from tblLogin where BookerID="+_BID+" and Pass="+_Pass,null);
Cursor c2 = myDB.query(DATABSE_TABLE_LOGIN, Columns_Login, BOOKER_ID + "=? AND "+ PASS+"=?", new String[]{_BID,_Pass}, null, null, null);

if(c2.getCount()>0){
Y_N=true ;
}
return Y_N;
}
}


When i call the method CreatEntry() then it gives me the following error:



android.database.sqlite.SQLiteException: table tblLogin has no column named BookerID: , while compiling:


Where is the Error ? And also when i call the method CheckLogin it also say that There is no column named BookerID.


Aucun commentaire:

Enregistrer un commentaire