samedi 6 juin 2015

android.database.sqlite.SQLiteException: no such table: LOGIN_TABLE_NAME (code 1): , while compiling: SELECT * FROM LOGIN_TABLE_NAME WHERE A_NAME=?

### database class ###
public class DBhandle {
//table name
private static final String LOGIN_TABLE_NAME = "Login";

//login table column name
public static final String KEY_ROWID= "ID";
public static final String A_NAME = "admin_name";
public static final String A_PHONE = "admin_phone";

db.execSQL("CREATE TABLE " + LOGIN_TABLE_NAME + " (" + KEY_ROWID
                        + " INTEGER PRIMARY KEY AUTOINCREMENT, " + A_NAME
                        + " TEXT NOT NULL, " + A_PHONE + " TEXT NOT NULL);"
                        );

public String getSingleEntry(String userName)
{
    Cursor cursor=ourDatabase.query("LOGIN_TABLE_NAME", null, " A_NAME=?", new String[]{userName}, null, null, null);
    if(cursor.getCount()<1) // UserName Not Exist
    {
        cursor.close();
        return "NOT EXIST";
    }
    cursor.moveToFirst();
    String password= cursor.getString(cursor.getColumnIndex("A_PHONE"));
    cursor.close();
    return password;                
}


### login class ###
@Override
public void onClick(View arg0) {
    // get user name password
    String userName=editTextUserNameToLogin.getText().toString();
    String password=editTextPasswordToLogin.getText().toString();

    // fetch the Password form database for respective user name
    String storedPass=dbhandle.getSingleEntry(userName);

// check if the Stored password matches with  Password entered by user
    if(password.equals(storedPass))
     {
     Toast.makeText(Login.this, "login successfull", Toast.LENGTH_LONG).show();}
            else
            {
                Toast.makeText(Login.this, "wrong username or password", Toast.LENGTH_LONG).show();
            }

when i run application and press button it crashes and these with error android.database.sqlite.SQLiteException: no such table: LOGIN_TABLE_NAME (code 1): , while compiling: SELECT * FROM LOGIN_TABLE_NAME WHERE A_NAME=?

at com.example.resturantms.Login$2.onClick(Login.java:69) ###

Aucun commentaire:

Enregistrer un commentaire