Having error on user when login and he is not on databasesqlite returned: error code = 1, msg = no such column:kitchen1How does database indexing work?How to list the tables in a SQLite database file that was opened with ATTACH?When to use LinkedList over ArrayList in Java?Why does Java have transient fields?“Debug certificate expired” error in Eclipse Android pluginsAndroid database recreates every time application is launchedWhat are the options for storing hierarchical data in a relational database?Why does my exception handler not trap Android SQLite insert error?Cursor for database on sdcard not closing or deactiveWhy doesn't RecyclerView have onItemClickListener()?
Why Is Death Allowed In the Matrix?
I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine
Explain the parameters before and after @ in the treminal
How much RAM could one put in a typical 80386 setup?
Why are weather verbs 曇る and 晴れる treated differently in this sentence?
Have astronauts in space suits ever taken selfies? If so, how?
Suffixes -unt and -ut-
Mathematical cryptic clues
A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?
Is there any sparring that doesn't involve punches to the head?
Theorems that impeded progress
Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?
How to re-create Edward Weson's Pepper No. 30?
Is there really no realistic way for a skeleton monster to move around without magic?
Why has Russell's definition of numbers using equivalence classes been finally abandonned? ( If it has actually been abandonned).
Why are 150k or 200k jobs considered good when there are 300k+ births a month?
Do I have a twin with permutated remainders?
Why can't I see bouncing of a switch on an oscilloscope?
XeLaTeX and pdfLaTeX ignore hyphenation
Can a German sentence have two subjects?
Do any Labour MPs support no-deal?
If I cast Expeditious Retreat, can I Dash as a bonus action on the same turn?
Is it legal for company to use my work email to pretend I still work there?
How to test if a transaction is standard without spending real money?
Having error on user when login and he is not on database
sqlite returned: error code = 1, msg = no such column:kitchen1How does database indexing work?How to list the tables in a SQLite database file that was opened with ATTACH?When to use LinkedList over ArrayList in Java?Why does Java have transient fields?“Debug certificate expired” error in Eclipse Android pluginsAndroid database recreates every time application is launchedWhat are the options for storing hierarchical data in a relational database?Why does my exception handler not trap Android SQLite insert error?Cursor for database on sdcard not closing or deactiveWhy doesn't RecyclerView have onItemClickListener()?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I got error when i tried to login with a wrong credential, i expected that in gonna receive toast error that wrong credential entered error but it crashes..
i think my database helper stops when it cant find the users email_phone and password. and doesnt send any denying function on my error login activity..
what is the denying fuction or something i am missing
heres my logcat
03-09 03:01:09.047 16124-16124/edu.angelo.parentsportal E/SQLiteLog: (1) no such column: parent
03-09 03:01:09.048 16124-16124/edu.angelo.parentsportal E/AndroidRuntime: FATAL EXCEPTION: main
Process: edu.angelo.parentsportal, PID: 16124
android.database.sqlite.SQLiteException: no such column: parent (code 1): , while compiling: select * from Parents_Table where (EMAIL_ADDRESS = parent OR PHONE_NUMBER = parent) AND PASSWORD = 123456
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1255)
at edu.angelo.parentsportal.DatabaseHelper.userExistance(DatabaseHelper.java:120)
at edu.angelo.parentsportal.Login.userLogin(Login.java:86)
at edu.angelo.parentsportal.Login.onClick(Login.java:50)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
my DatabaseHelper
package edu.angelo.parentsportal;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.ArrayList;
public class DatabaseHelper extends SQLiteOpenHelper
public static final String DATABASE_NAME = "Parents_Portal.db";
public static final String TABLE_NAME = "Parents_Table";
public static final String COL_0 = "ID";
public static final String COL_1 = "NAME";
public static final String COL_2 = "SURNAME";
public static final String COL_3 = "EMAIL_ADDRESS";
public static final String COL_4 = "PHONE_NUMBER";
public static final String COL_5 = "PASSWORD";
public DatabaseHelper(Context context)
super(context, DATABASE_NAME, null, 1);
@Override
public void onCreate(SQLiteDatabase db)
db.execSQL("create table " + TABLE_NAME +"(ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, SURNAME TEXT, EMAIL_ADDRESS TEXT, PHONE_NUMBER TEXT, PASSWORD TEXT)");
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);
onCreate(db);
public boolean insertData(String name, String surname, String email_address, String phone_number, String password)
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_1,name);
contentValues.put(COL_2,surname);
contentValues.put(COL_3,email_address);
contentValues.put(COL_4,phone_number);
contentValues.put(COL_5,password);
long result = db.insert(TABLE_NAME, null , contentValues);
if (result == -1)
return false;
else
return true;
public ArrayList<ParentModel> getAllParentsData()
ArrayList<ParentModel> list = new ArrayList<>();
String sql = "select * from " + TABLE_NAME;
SQLiteDatabase mydb = this.getWritableDatabase();
Cursor cursor = mydb.rawQuery(sql, null);
if (cursor.moveToFirst())
do
ParentModel parentModel = new ParentModel();
parentModel.setID(cursor.getString(0));
parentModel.setName(cursor.getString(1));
parentModel.setSurname(cursor.getString(2));
parentModel.setEmail(cursor.getString(3));
parentModel.setPhone_number(cursor.getString(4));
parentModel.setPassword(cursor.getString(5));
list.add(parentModel);
while (cursor.moveToNext());
return list;
public void updateData(int id, String name , String surname , String email , String phone_number , String password)
ContentValues contentValues = new ContentValues();
contentValues.put(COL_1, name);
contentValues.put(COL_2, surname);
contentValues.put(COL_3, email);
contentValues.put(COL_4, phone_number);
contentValues.put(COL_5, password);
SQLiteDatabase mydb = this.getWritableDatabase();
mydb.update(TABLE_NAME, contentValues, COL_0 + "=" + id, null);
mydb.close();
public void deleteParent(int id)
SQLiteDatabase mydb = this.getWritableDatabase();
mydb.delete(TABLE_NAME, COL_0 + "=" + id, null);
mydb.close();
public ArrayList<ParentModel> getParentLoginData(String emailOrPhone,String password)
ArrayList<ParentModel> list = new ArrayList<>();
String sql = "SELECT * FROM " + TABLE_NAME+" WHERE ("+COL_3+"= "+emailOrPhone+" OR "+COL_4 +" = "+emailOrPhone+") AND "+COL_5 +" = "+ password;
SQLiteDatabase mydb = this.getWritableDatabase();
Cursor cursor = mydb.rawQuery(sql, null);
if (cursor.getCount() > 0)
do
ParentModel parentModel = new ParentModel();
parentModel.setID(cursor.getString(0));
parentModel.setName(cursor.getString(1));
parentModel.setSurname(cursor.getString(2));
parentModel.setEmail(cursor.getString(3));
parentModel.setPhone_number(cursor.getString(4));
parentModel.setPassword(cursor.getString(5));
list.add(parentModel);
while (cursor.moveToNext());
return list;
public boolean userExistance(String emailOrPhone, String pwd)
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = " + emailOrPhone + " OR " + COL_4 + " = " + emailOrPhone + ") AND " + COL_5 + " = " + pwd;
SQLiteDatabase mydb = this.getWritableDatabase();
Cursor cursor = mydb.rawQuery(sql, null);
if (cursor.getCount() > 0)
do
ArrayList<ParentModel> list = new ArrayList<>();
ParentModel parentModel = new ParentModel();
parentModel.setID(cursor.getString(0));
parentModel.setName(cursor.getString(1));
parentModel.setSurname(cursor.getString(2));
parentModel.setEmail(cursor.getString(3));
parentModel.setPhone_number(cursor.getString(4));
parentModel.setPassword(cursor.getString(5));
list.add(parentModel);
while (cursor.moveToNext());
return true;
else
return false;
My loginActivity
public class Login extends AppCompatActivity implements View.OnClickListener
private EditText editTextEmailPhone;
private EditText editTextPassword;
private Button Login;
private ProgressDialog progressDialog;
DatabaseHelper mydb;
SQLiteDatabase sqLiteDatabase;
ParentModel parentModel;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
editTextEmailPhone = findViewById(R.id.input_username);
editTextPassword = findViewById(R.id.input_password);
findViewById(R.id.btn_register).setOnClickListener(Login.this);
progressDialog = new ProgressDialog(this);
mydb = new DatabaseHelper(this);
sqLiteDatabase = mydb.getReadableDatabase();
@Override
public void onClick(View view)
switch (view.getId())
case R.id.btn_register:
userLogin();
break;
private void userLogin()
String email = editTextEmailPhone.getText().toString().trim();
String password = editTextPassword.getText().toString().trim();
if (email.isEmpty())
editTextEmailPhone.setError("Email or Phone Number is required");
editTextEmailPhone.requestFocus();
return;
if (password.isEmpty())
editTextPassword.setError("Password is required");
editTextPassword.requestFocus();
return;
if (password.length()<6 )
editTextPassword.setError("Minimum of length of password should be 6");
editTextPassword.requestFocus();
return;
//if the email&pass is not empty
else
progressDialog.setMessage("Please Wait...");
progressDialog.show();
boolean exists = mydb.userExistance(email, password);
if(true)
progressDialog.dismiss();
SharedPrefs.saveSharedSetting(this, "NoAccount", "false");
Intent intent = new Intent(Login.this, Parent_Home.class);
String parentID;
String parentName;
String parentSurname;
parentID = parentModel.getID();
parentName = parentModel.getName();
parentSurname = parentModel.getSurname();
//Change to prefs
//intent.putExtra("Ik_CurrentParentID",parentModel.getID());
// intent.putExtra("Ik_CurrentParentName",parentModel.getName());
// intent.putExtra("Ik_CurrentParentSurname",parentModel.getSurname());
// Toast.makeText(this, "Welcome" + parentName, Toast.LENGTH_SHORT).show();
startActivity(intent);
finish();
else
Toast.makeText(getApplicationContext(), "Login error", Toast.LENGTH_SHORT).show();
progressDialog.dismiss();
return;
java android database sqlite
add a comment |
I got error when i tried to login with a wrong credential, i expected that in gonna receive toast error that wrong credential entered error but it crashes..
i think my database helper stops when it cant find the users email_phone and password. and doesnt send any denying function on my error login activity..
what is the denying fuction or something i am missing
heres my logcat
03-09 03:01:09.047 16124-16124/edu.angelo.parentsportal E/SQLiteLog: (1) no such column: parent
03-09 03:01:09.048 16124-16124/edu.angelo.parentsportal E/AndroidRuntime: FATAL EXCEPTION: main
Process: edu.angelo.parentsportal, PID: 16124
android.database.sqlite.SQLiteException: no such column: parent (code 1): , while compiling: select * from Parents_Table where (EMAIL_ADDRESS = parent OR PHONE_NUMBER = parent) AND PASSWORD = 123456
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1255)
at edu.angelo.parentsportal.DatabaseHelper.userExistance(DatabaseHelper.java:120)
at edu.angelo.parentsportal.Login.userLogin(Login.java:86)
at edu.angelo.parentsportal.Login.onClick(Login.java:50)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
my DatabaseHelper
package edu.angelo.parentsportal;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.ArrayList;
public class DatabaseHelper extends SQLiteOpenHelper
public static final String DATABASE_NAME = "Parents_Portal.db";
public static final String TABLE_NAME = "Parents_Table";
public static final String COL_0 = "ID";
public static final String COL_1 = "NAME";
public static final String COL_2 = "SURNAME";
public static final String COL_3 = "EMAIL_ADDRESS";
public static final String COL_4 = "PHONE_NUMBER";
public static final String COL_5 = "PASSWORD";
public DatabaseHelper(Context context)
super(context, DATABASE_NAME, null, 1);
@Override
public void onCreate(SQLiteDatabase db)
db.execSQL("create table " + TABLE_NAME +"(ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, SURNAME TEXT, EMAIL_ADDRESS TEXT, PHONE_NUMBER TEXT, PASSWORD TEXT)");
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);
onCreate(db);
public boolean insertData(String name, String surname, String email_address, String phone_number, String password)
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_1,name);
contentValues.put(COL_2,surname);
contentValues.put(COL_3,email_address);
contentValues.put(COL_4,phone_number);
contentValues.put(COL_5,password);
long result = db.insert(TABLE_NAME, null , contentValues);
if (result == -1)
return false;
else
return true;
public ArrayList<ParentModel> getAllParentsData()
ArrayList<ParentModel> list = new ArrayList<>();
String sql = "select * from " + TABLE_NAME;
SQLiteDatabase mydb = this.getWritableDatabase();
Cursor cursor = mydb.rawQuery(sql, null);
if (cursor.moveToFirst())
do
ParentModel parentModel = new ParentModel();
parentModel.setID(cursor.getString(0));
parentModel.setName(cursor.getString(1));
parentModel.setSurname(cursor.getString(2));
parentModel.setEmail(cursor.getString(3));
parentModel.setPhone_number(cursor.getString(4));
parentModel.setPassword(cursor.getString(5));
list.add(parentModel);
while (cursor.moveToNext());
return list;
public void updateData(int id, String name , String surname , String email , String phone_number , String password)
ContentValues contentValues = new ContentValues();
contentValues.put(COL_1, name);
contentValues.put(COL_2, surname);
contentValues.put(COL_3, email);
contentValues.put(COL_4, phone_number);
contentValues.put(COL_5, password);
SQLiteDatabase mydb = this.getWritableDatabase();
mydb.update(TABLE_NAME, contentValues, COL_0 + "=" + id, null);
mydb.close();
public void deleteParent(int id)
SQLiteDatabase mydb = this.getWritableDatabase();
mydb.delete(TABLE_NAME, COL_0 + "=" + id, null);
mydb.close();
public ArrayList<ParentModel> getParentLoginData(String emailOrPhone,String password)
ArrayList<ParentModel> list = new ArrayList<>();
String sql = "SELECT * FROM " + TABLE_NAME+" WHERE ("+COL_3+"= "+emailOrPhone+" OR "+COL_4 +" = "+emailOrPhone+") AND "+COL_5 +" = "+ password;
SQLiteDatabase mydb = this.getWritableDatabase();
Cursor cursor = mydb.rawQuery(sql, null);
if (cursor.getCount() > 0)
do
ParentModel parentModel = new ParentModel();
parentModel.setID(cursor.getString(0));
parentModel.setName(cursor.getString(1));
parentModel.setSurname(cursor.getString(2));
parentModel.setEmail(cursor.getString(3));
parentModel.setPhone_number(cursor.getString(4));
parentModel.setPassword(cursor.getString(5));
list.add(parentModel);
while (cursor.moveToNext());
return list;
public boolean userExistance(String emailOrPhone, String pwd)
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = " + emailOrPhone + " OR " + COL_4 + " = " + emailOrPhone + ") AND " + COL_5 + " = " + pwd;
SQLiteDatabase mydb = this.getWritableDatabase();
Cursor cursor = mydb.rawQuery(sql, null);
if (cursor.getCount() > 0)
do
ArrayList<ParentModel> list = new ArrayList<>();
ParentModel parentModel = new ParentModel();
parentModel.setID(cursor.getString(0));
parentModel.setName(cursor.getString(1));
parentModel.setSurname(cursor.getString(2));
parentModel.setEmail(cursor.getString(3));
parentModel.setPhone_number(cursor.getString(4));
parentModel.setPassword(cursor.getString(5));
list.add(parentModel);
while (cursor.moveToNext());
return true;
else
return false;
My loginActivity
public class Login extends AppCompatActivity implements View.OnClickListener
private EditText editTextEmailPhone;
private EditText editTextPassword;
private Button Login;
private ProgressDialog progressDialog;
DatabaseHelper mydb;
SQLiteDatabase sqLiteDatabase;
ParentModel parentModel;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
editTextEmailPhone = findViewById(R.id.input_username);
editTextPassword = findViewById(R.id.input_password);
findViewById(R.id.btn_register).setOnClickListener(Login.this);
progressDialog = new ProgressDialog(this);
mydb = new DatabaseHelper(this);
sqLiteDatabase = mydb.getReadableDatabase();
@Override
public void onClick(View view)
switch (view.getId())
case R.id.btn_register:
userLogin();
break;
private void userLogin()
String email = editTextEmailPhone.getText().toString().trim();
String password = editTextPassword.getText().toString().trim();
if (email.isEmpty())
editTextEmailPhone.setError("Email or Phone Number is required");
editTextEmailPhone.requestFocus();
return;
if (password.isEmpty())
editTextPassword.setError("Password is required");
editTextPassword.requestFocus();
return;
if (password.length()<6 )
editTextPassword.setError("Minimum of length of password should be 6");
editTextPassword.requestFocus();
return;
//if the email&pass is not empty
else
progressDialog.setMessage("Please Wait...");
progressDialog.show();
boolean exists = mydb.userExistance(email, password);
if(true)
progressDialog.dismiss();
SharedPrefs.saveSharedSetting(this, "NoAccount", "false");
Intent intent = new Intent(Login.this, Parent_Home.class);
String parentID;
String parentName;
String parentSurname;
parentID = parentModel.getID();
parentName = parentModel.getName();
parentSurname = parentModel.getSurname();
//Change to prefs
//intent.putExtra("Ik_CurrentParentID",parentModel.getID());
// intent.putExtra("Ik_CurrentParentName",parentModel.getName());
// intent.putExtra("Ik_CurrentParentSurname",parentModel.getSurname());
// Toast.makeText(this, "Welcome" + parentName, Toast.LENGTH_SHORT).show();
startActivity(intent);
finish();
else
Toast.makeText(getApplicationContext(), "Login error", Toast.LENGTH_SHORT).show();
progressDialog.dismiss();
return;
java android database sqlite
add a comment |
I got error when i tried to login with a wrong credential, i expected that in gonna receive toast error that wrong credential entered error but it crashes..
i think my database helper stops when it cant find the users email_phone and password. and doesnt send any denying function on my error login activity..
what is the denying fuction or something i am missing
heres my logcat
03-09 03:01:09.047 16124-16124/edu.angelo.parentsportal E/SQLiteLog: (1) no such column: parent
03-09 03:01:09.048 16124-16124/edu.angelo.parentsportal E/AndroidRuntime: FATAL EXCEPTION: main
Process: edu.angelo.parentsportal, PID: 16124
android.database.sqlite.SQLiteException: no such column: parent (code 1): , while compiling: select * from Parents_Table where (EMAIL_ADDRESS = parent OR PHONE_NUMBER = parent) AND PASSWORD = 123456
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1255)
at edu.angelo.parentsportal.DatabaseHelper.userExistance(DatabaseHelper.java:120)
at edu.angelo.parentsportal.Login.userLogin(Login.java:86)
at edu.angelo.parentsportal.Login.onClick(Login.java:50)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
my DatabaseHelper
package edu.angelo.parentsportal;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.ArrayList;
public class DatabaseHelper extends SQLiteOpenHelper
public static final String DATABASE_NAME = "Parents_Portal.db";
public static final String TABLE_NAME = "Parents_Table";
public static final String COL_0 = "ID";
public static final String COL_1 = "NAME";
public static final String COL_2 = "SURNAME";
public static final String COL_3 = "EMAIL_ADDRESS";
public static final String COL_4 = "PHONE_NUMBER";
public static final String COL_5 = "PASSWORD";
public DatabaseHelper(Context context)
super(context, DATABASE_NAME, null, 1);
@Override
public void onCreate(SQLiteDatabase db)
db.execSQL("create table " + TABLE_NAME +"(ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, SURNAME TEXT, EMAIL_ADDRESS TEXT, PHONE_NUMBER TEXT, PASSWORD TEXT)");
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);
onCreate(db);
public boolean insertData(String name, String surname, String email_address, String phone_number, String password)
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_1,name);
contentValues.put(COL_2,surname);
contentValues.put(COL_3,email_address);
contentValues.put(COL_4,phone_number);
contentValues.put(COL_5,password);
long result = db.insert(TABLE_NAME, null , contentValues);
if (result == -1)
return false;
else
return true;
public ArrayList<ParentModel> getAllParentsData()
ArrayList<ParentModel> list = new ArrayList<>();
String sql = "select * from " + TABLE_NAME;
SQLiteDatabase mydb = this.getWritableDatabase();
Cursor cursor = mydb.rawQuery(sql, null);
if (cursor.moveToFirst())
do
ParentModel parentModel = new ParentModel();
parentModel.setID(cursor.getString(0));
parentModel.setName(cursor.getString(1));
parentModel.setSurname(cursor.getString(2));
parentModel.setEmail(cursor.getString(3));
parentModel.setPhone_number(cursor.getString(4));
parentModel.setPassword(cursor.getString(5));
list.add(parentModel);
while (cursor.moveToNext());
return list;
public void updateData(int id, String name , String surname , String email , String phone_number , String password)
ContentValues contentValues = new ContentValues();
contentValues.put(COL_1, name);
contentValues.put(COL_2, surname);
contentValues.put(COL_3, email);
contentValues.put(COL_4, phone_number);
contentValues.put(COL_5, password);
SQLiteDatabase mydb = this.getWritableDatabase();
mydb.update(TABLE_NAME, contentValues, COL_0 + "=" + id, null);
mydb.close();
public void deleteParent(int id)
SQLiteDatabase mydb = this.getWritableDatabase();
mydb.delete(TABLE_NAME, COL_0 + "=" + id, null);
mydb.close();
public ArrayList<ParentModel> getParentLoginData(String emailOrPhone,String password)
ArrayList<ParentModel> list = new ArrayList<>();
String sql = "SELECT * FROM " + TABLE_NAME+" WHERE ("+COL_3+"= "+emailOrPhone+" OR "+COL_4 +" = "+emailOrPhone+") AND "+COL_5 +" = "+ password;
SQLiteDatabase mydb = this.getWritableDatabase();
Cursor cursor = mydb.rawQuery(sql, null);
if (cursor.getCount() > 0)
do
ParentModel parentModel = new ParentModel();
parentModel.setID(cursor.getString(0));
parentModel.setName(cursor.getString(1));
parentModel.setSurname(cursor.getString(2));
parentModel.setEmail(cursor.getString(3));
parentModel.setPhone_number(cursor.getString(4));
parentModel.setPassword(cursor.getString(5));
list.add(parentModel);
while (cursor.moveToNext());
return list;
public boolean userExistance(String emailOrPhone, String pwd)
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = " + emailOrPhone + " OR " + COL_4 + " = " + emailOrPhone + ") AND " + COL_5 + " = " + pwd;
SQLiteDatabase mydb = this.getWritableDatabase();
Cursor cursor = mydb.rawQuery(sql, null);
if (cursor.getCount() > 0)
do
ArrayList<ParentModel> list = new ArrayList<>();
ParentModel parentModel = new ParentModel();
parentModel.setID(cursor.getString(0));
parentModel.setName(cursor.getString(1));
parentModel.setSurname(cursor.getString(2));
parentModel.setEmail(cursor.getString(3));
parentModel.setPhone_number(cursor.getString(4));
parentModel.setPassword(cursor.getString(5));
list.add(parentModel);
while (cursor.moveToNext());
return true;
else
return false;
My loginActivity
public class Login extends AppCompatActivity implements View.OnClickListener
private EditText editTextEmailPhone;
private EditText editTextPassword;
private Button Login;
private ProgressDialog progressDialog;
DatabaseHelper mydb;
SQLiteDatabase sqLiteDatabase;
ParentModel parentModel;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
editTextEmailPhone = findViewById(R.id.input_username);
editTextPassword = findViewById(R.id.input_password);
findViewById(R.id.btn_register).setOnClickListener(Login.this);
progressDialog = new ProgressDialog(this);
mydb = new DatabaseHelper(this);
sqLiteDatabase = mydb.getReadableDatabase();
@Override
public void onClick(View view)
switch (view.getId())
case R.id.btn_register:
userLogin();
break;
private void userLogin()
String email = editTextEmailPhone.getText().toString().trim();
String password = editTextPassword.getText().toString().trim();
if (email.isEmpty())
editTextEmailPhone.setError("Email or Phone Number is required");
editTextEmailPhone.requestFocus();
return;
if (password.isEmpty())
editTextPassword.setError("Password is required");
editTextPassword.requestFocus();
return;
if (password.length()<6 )
editTextPassword.setError("Minimum of length of password should be 6");
editTextPassword.requestFocus();
return;
//if the email&pass is not empty
else
progressDialog.setMessage("Please Wait...");
progressDialog.show();
boolean exists = mydb.userExistance(email, password);
if(true)
progressDialog.dismiss();
SharedPrefs.saveSharedSetting(this, "NoAccount", "false");
Intent intent = new Intent(Login.this, Parent_Home.class);
String parentID;
String parentName;
String parentSurname;
parentID = parentModel.getID();
parentName = parentModel.getName();
parentSurname = parentModel.getSurname();
//Change to prefs
//intent.putExtra("Ik_CurrentParentID",parentModel.getID());
// intent.putExtra("Ik_CurrentParentName",parentModel.getName());
// intent.putExtra("Ik_CurrentParentSurname",parentModel.getSurname());
// Toast.makeText(this, "Welcome" + parentName, Toast.LENGTH_SHORT).show();
startActivity(intent);
finish();
else
Toast.makeText(getApplicationContext(), "Login error", Toast.LENGTH_SHORT).show();
progressDialog.dismiss();
return;
java android database sqlite
I got error when i tried to login with a wrong credential, i expected that in gonna receive toast error that wrong credential entered error but it crashes..
i think my database helper stops when it cant find the users email_phone and password. and doesnt send any denying function on my error login activity..
what is the denying fuction or something i am missing
heres my logcat
03-09 03:01:09.047 16124-16124/edu.angelo.parentsportal E/SQLiteLog: (1) no such column: parent
03-09 03:01:09.048 16124-16124/edu.angelo.parentsportal E/AndroidRuntime: FATAL EXCEPTION: main
Process: edu.angelo.parentsportal, PID: 16124
android.database.sqlite.SQLiteException: no such column: parent (code 1): , while compiling: select * from Parents_Table where (EMAIL_ADDRESS = parent OR PHONE_NUMBER = parent) AND PASSWORD = 123456
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1255)
at edu.angelo.parentsportal.DatabaseHelper.userExistance(DatabaseHelper.java:120)
at edu.angelo.parentsportal.Login.userLogin(Login.java:86)
at edu.angelo.parentsportal.Login.onClick(Login.java:50)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
my DatabaseHelper
package edu.angelo.parentsportal;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.ArrayList;
public class DatabaseHelper extends SQLiteOpenHelper
public static final String DATABASE_NAME = "Parents_Portal.db";
public static final String TABLE_NAME = "Parents_Table";
public static final String COL_0 = "ID";
public static final String COL_1 = "NAME";
public static final String COL_2 = "SURNAME";
public static final String COL_3 = "EMAIL_ADDRESS";
public static final String COL_4 = "PHONE_NUMBER";
public static final String COL_5 = "PASSWORD";
public DatabaseHelper(Context context)
super(context, DATABASE_NAME, null, 1);
@Override
public void onCreate(SQLiteDatabase db)
db.execSQL("create table " + TABLE_NAME +"(ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, SURNAME TEXT, EMAIL_ADDRESS TEXT, PHONE_NUMBER TEXT, PASSWORD TEXT)");
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);
onCreate(db);
public boolean insertData(String name, String surname, String email_address, String phone_number, String password)
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_1,name);
contentValues.put(COL_2,surname);
contentValues.put(COL_3,email_address);
contentValues.put(COL_4,phone_number);
contentValues.put(COL_5,password);
long result = db.insert(TABLE_NAME, null , contentValues);
if (result == -1)
return false;
else
return true;
public ArrayList<ParentModel> getAllParentsData()
ArrayList<ParentModel> list = new ArrayList<>();
String sql = "select * from " + TABLE_NAME;
SQLiteDatabase mydb = this.getWritableDatabase();
Cursor cursor = mydb.rawQuery(sql, null);
if (cursor.moveToFirst())
do
ParentModel parentModel = new ParentModel();
parentModel.setID(cursor.getString(0));
parentModel.setName(cursor.getString(1));
parentModel.setSurname(cursor.getString(2));
parentModel.setEmail(cursor.getString(3));
parentModel.setPhone_number(cursor.getString(4));
parentModel.setPassword(cursor.getString(5));
list.add(parentModel);
while (cursor.moveToNext());
return list;
public void updateData(int id, String name , String surname , String email , String phone_number , String password)
ContentValues contentValues = new ContentValues();
contentValues.put(COL_1, name);
contentValues.put(COL_2, surname);
contentValues.put(COL_3, email);
contentValues.put(COL_4, phone_number);
contentValues.put(COL_5, password);
SQLiteDatabase mydb = this.getWritableDatabase();
mydb.update(TABLE_NAME, contentValues, COL_0 + "=" + id, null);
mydb.close();
public void deleteParent(int id)
SQLiteDatabase mydb = this.getWritableDatabase();
mydb.delete(TABLE_NAME, COL_0 + "=" + id, null);
mydb.close();
public ArrayList<ParentModel> getParentLoginData(String emailOrPhone,String password)
ArrayList<ParentModel> list = new ArrayList<>();
String sql = "SELECT * FROM " + TABLE_NAME+" WHERE ("+COL_3+"= "+emailOrPhone+" OR "+COL_4 +" = "+emailOrPhone+") AND "+COL_5 +" = "+ password;
SQLiteDatabase mydb = this.getWritableDatabase();
Cursor cursor = mydb.rawQuery(sql, null);
if (cursor.getCount() > 0)
do
ParentModel parentModel = new ParentModel();
parentModel.setID(cursor.getString(0));
parentModel.setName(cursor.getString(1));
parentModel.setSurname(cursor.getString(2));
parentModel.setEmail(cursor.getString(3));
parentModel.setPhone_number(cursor.getString(4));
parentModel.setPassword(cursor.getString(5));
list.add(parentModel);
while (cursor.moveToNext());
return list;
public boolean userExistance(String emailOrPhone, String pwd)
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = " + emailOrPhone + " OR " + COL_4 + " = " + emailOrPhone + ") AND " + COL_5 + " = " + pwd;
SQLiteDatabase mydb = this.getWritableDatabase();
Cursor cursor = mydb.rawQuery(sql, null);
if (cursor.getCount() > 0)
do
ArrayList<ParentModel> list = new ArrayList<>();
ParentModel parentModel = new ParentModel();
parentModel.setID(cursor.getString(0));
parentModel.setName(cursor.getString(1));
parentModel.setSurname(cursor.getString(2));
parentModel.setEmail(cursor.getString(3));
parentModel.setPhone_number(cursor.getString(4));
parentModel.setPassword(cursor.getString(5));
list.add(parentModel);
while (cursor.moveToNext());
return true;
else
return false;
My loginActivity
public class Login extends AppCompatActivity implements View.OnClickListener
private EditText editTextEmailPhone;
private EditText editTextPassword;
private Button Login;
private ProgressDialog progressDialog;
DatabaseHelper mydb;
SQLiteDatabase sqLiteDatabase;
ParentModel parentModel;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
editTextEmailPhone = findViewById(R.id.input_username);
editTextPassword = findViewById(R.id.input_password);
findViewById(R.id.btn_register).setOnClickListener(Login.this);
progressDialog = new ProgressDialog(this);
mydb = new DatabaseHelper(this);
sqLiteDatabase = mydb.getReadableDatabase();
@Override
public void onClick(View view)
switch (view.getId())
case R.id.btn_register:
userLogin();
break;
private void userLogin()
String email = editTextEmailPhone.getText().toString().trim();
String password = editTextPassword.getText().toString().trim();
if (email.isEmpty())
editTextEmailPhone.setError("Email or Phone Number is required");
editTextEmailPhone.requestFocus();
return;
if (password.isEmpty())
editTextPassword.setError("Password is required");
editTextPassword.requestFocus();
return;
if (password.length()<6 )
editTextPassword.setError("Minimum of length of password should be 6");
editTextPassword.requestFocus();
return;
//if the email&pass is not empty
else
progressDialog.setMessage("Please Wait...");
progressDialog.show();
boolean exists = mydb.userExistance(email, password);
if(true)
progressDialog.dismiss();
SharedPrefs.saveSharedSetting(this, "NoAccount", "false");
Intent intent = new Intent(Login.this, Parent_Home.class);
String parentID;
String parentName;
String parentSurname;
parentID = parentModel.getID();
parentName = parentModel.getName();
parentSurname = parentModel.getSurname();
//Change to prefs
//intent.putExtra("Ik_CurrentParentID",parentModel.getID());
// intent.putExtra("Ik_CurrentParentName",parentModel.getName());
// intent.putExtra("Ik_CurrentParentSurname",parentModel.getSurname());
// Toast.makeText(this, "Welcome" + parentName, Toast.LENGTH_SHORT).show();
startActivity(intent);
finish();
else
Toast.makeText(getApplicationContext(), "Login error", Toast.LENGTH_SHORT).show();
progressDialog.dismiss();
return;
java android database sqlite
java android database sqlite
edited Mar 9 at 5:01
MikeT
18.6k112844
18.6k112844
asked Mar 9 at 3:25
Angelo DionisioAngelo Dionisio
84
84
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
The cause is that as parent is not enclosed in single quotes, it is considered as an identifier (in this case a column name as you could compare against a column via it's name, hence the message).
1. The quick but not so good fix.
It appears that you have such three instances so you could change :-
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = " + emailOrPhone + " OR " + COL_4 + " = " + emailOrPhone + ") AND " + COL_5 + " = " + pwd;
to be
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = '" + emailOrPhone + "' OR " + COL_4 + " = '" + emailOrPhone + "') AND " + COL_5 + " = '" + pwd + "'";
2. A better fix, but still some potential issues (see next fix)
However, should the values to compare against be via user input. This leaves the App open to SQL Injection (entering damaging commands via input), as such it is suggested that you utilise the 2nd parameter of rawQuewry method to pass a String array of values that will on a one per basis replace ?'s in the query.
As such it would be considered a safer practice to use :-
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = ? OR " + COL_4 + " =?) AND " + COL_5 + " =? ";
String[] args = new String[]emailOrPhone,emailOrPhone,pwd;
SQLiteDatabase mydb = this.getWritableDatabase();
Cursor cursor = mydb.rawQuery(sql,args);
3. The better fix.
However, there are convenience methods such as query (yuo used the update convenience method), that are considered better than using rawQuery where possible.
The convenience methods build the underlying SQL. As such the recommended way would be to use :-
public boolean userExistance(String emailOrPhone, String pwd)
SQLiteDatabase mydb = this.getWritableDatabase();
String whereclause = "(" + COL_3 + "=? OR " + COL_4 + "=?) AND " + COL_5 + "=?";
String[] whereargs = new String[]emailOrPhone,emailOrPhone,pwd
Cursor cursor = mydb.query(TABLE_NAME,null,whereclause,whereargs,null,null,null);
boolean rv = cusror.getCount() > 0;
cursor.close();
return rv;
- Note that this has also been altered to do away with needless and potentially dangerous code.
- The Cursor is closed, if too many Cursors are left open the App will crash, so it is bad practice to not close Cursors when done with them.
- There is no need to loop through the cursor and extract the data, as all you want to know if any rows have been returned. So the count is used to set the return value to true or false, the cursor is closed and the boolean returned.
- You may wish to have a look at SQLiteDatabase - query
Note the above is in-principle code, it has not been tested or run and may therefore contain some errors.
You should also note that you will have a similar issue with getParentLoginData as the SELECT clause is very much the same.
add a comment |
I think you need to add one (') before and after emailOrPhone
because it's a character type. and the query would be like:
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = '" + emailOrPhone + "' OR " + COL_4 + " = '" + emailOrPhone + "') AND " + COL_5 + " = " + pwd;
for more information you can check this problem: sqlite returned: error code = 1, msg = no such column:kitchen1
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073697%2fhaving-error-on-user-when-login-and-he-is-not-on-database%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The cause is that as parent is not enclosed in single quotes, it is considered as an identifier (in this case a column name as you could compare against a column via it's name, hence the message).
1. The quick but not so good fix.
It appears that you have such three instances so you could change :-
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = " + emailOrPhone + " OR " + COL_4 + " = " + emailOrPhone + ") AND " + COL_5 + " = " + pwd;
to be
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = '" + emailOrPhone + "' OR " + COL_4 + " = '" + emailOrPhone + "') AND " + COL_5 + " = '" + pwd + "'";
2. A better fix, but still some potential issues (see next fix)
However, should the values to compare against be via user input. This leaves the App open to SQL Injection (entering damaging commands via input), as such it is suggested that you utilise the 2nd parameter of rawQuewry method to pass a String array of values that will on a one per basis replace ?'s in the query.
As such it would be considered a safer practice to use :-
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = ? OR " + COL_4 + " =?) AND " + COL_5 + " =? ";
String[] args = new String[]emailOrPhone,emailOrPhone,pwd;
SQLiteDatabase mydb = this.getWritableDatabase();
Cursor cursor = mydb.rawQuery(sql,args);
3. The better fix.
However, there are convenience methods such as query (yuo used the update convenience method), that are considered better than using rawQuery where possible.
The convenience methods build the underlying SQL. As such the recommended way would be to use :-
public boolean userExistance(String emailOrPhone, String pwd)
SQLiteDatabase mydb = this.getWritableDatabase();
String whereclause = "(" + COL_3 + "=? OR " + COL_4 + "=?) AND " + COL_5 + "=?";
String[] whereargs = new String[]emailOrPhone,emailOrPhone,pwd
Cursor cursor = mydb.query(TABLE_NAME,null,whereclause,whereargs,null,null,null);
boolean rv = cusror.getCount() > 0;
cursor.close();
return rv;
- Note that this has also been altered to do away with needless and potentially dangerous code.
- The Cursor is closed, if too many Cursors are left open the App will crash, so it is bad practice to not close Cursors when done with them.
- There is no need to loop through the cursor and extract the data, as all you want to know if any rows have been returned. So the count is used to set the return value to true or false, the cursor is closed and the boolean returned.
- You may wish to have a look at SQLiteDatabase - query
Note the above is in-principle code, it has not been tested or run and may therefore contain some errors.
You should also note that you will have a similar issue with getParentLoginData as the SELECT clause is very much the same.
add a comment |
The cause is that as parent is not enclosed in single quotes, it is considered as an identifier (in this case a column name as you could compare against a column via it's name, hence the message).
1. The quick but not so good fix.
It appears that you have such three instances so you could change :-
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = " + emailOrPhone + " OR " + COL_4 + " = " + emailOrPhone + ") AND " + COL_5 + " = " + pwd;
to be
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = '" + emailOrPhone + "' OR " + COL_4 + " = '" + emailOrPhone + "') AND " + COL_5 + " = '" + pwd + "'";
2. A better fix, but still some potential issues (see next fix)
However, should the values to compare against be via user input. This leaves the App open to SQL Injection (entering damaging commands via input), as such it is suggested that you utilise the 2nd parameter of rawQuewry method to pass a String array of values that will on a one per basis replace ?'s in the query.
As such it would be considered a safer practice to use :-
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = ? OR " + COL_4 + " =?) AND " + COL_5 + " =? ";
String[] args = new String[]emailOrPhone,emailOrPhone,pwd;
SQLiteDatabase mydb = this.getWritableDatabase();
Cursor cursor = mydb.rawQuery(sql,args);
3. The better fix.
However, there are convenience methods such as query (yuo used the update convenience method), that are considered better than using rawQuery where possible.
The convenience methods build the underlying SQL. As such the recommended way would be to use :-
public boolean userExistance(String emailOrPhone, String pwd)
SQLiteDatabase mydb = this.getWritableDatabase();
String whereclause = "(" + COL_3 + "=? OR " + COL_4 + "=?) AND " + COL_5 + "=?";
String[] whereargs = new String[]emailOrPhone,emailOrPhone,pwd
Cursor cursor = mydb.query(TABLE_NAME,null,whereclause,whereargs,null,null,null);
boolean rv = cusror.getCount() > 0;
cursor.close();
return rv;
- Note that this has also been altered to do away with needless and potentially dangerous code.
- The Cursor is closed, if too many Cursors are left open the App will crash, so it is bad practice to not close Cursors when done with them.
- There is no need to loop through the cursor and extract the data, as all you want to know if any rows have been returned. So the count is used to set the return value to true or false, the cursor is closed and the boolean returned.
- You may wish to have a look at SQLiteDatabase - query
Note the above is in-principle code, it has not been tested or run and may therefore contain some errors.
You should also note that you will have a similar issue with getParentLoginData as the SELECT clause is very much the same.
add a comment |
The cause is that as parent is not enclosed in single quotes, it is considered as an identifier (in this case a column name as you could compare against a column via it's name, hence the message).
1. The quick but not so good fix.
It appears that you have such three instances so you could change :-
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = " + emailOrPhone + " OR " + COL_4 + " = " + emailOrPhone + ") AND " + COL_5 + " = " + pwd;
to be
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = '" + emailOrPhone + "' OR " + COL_4 + " = '" + emailOrPhone + "') AND " + COL_5 + " = '" + pwd + "'";
2. A better fix, but still some potential issues (see next fix)
However, should the values to compare against be via user input. This leaves the App open to SQL Injection (entering damaging commands via input), as such it is suggested that you utilise the 2nd parameter of rawQuewry method to pass a String array of values that will on a one per basis replace ?'s in the query.
As such it would be considered a safer practice to use :-
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = ? OR " + COL_4 + " =?) AND " + COL_5 + " =? ";
String[] args = new String[]emailOrPhone,emailOrPhone,pwd;
SQLiteDatabase mydb = this.getWritableDatabase();
Cursor cursor = mydb.rawQuery(sql,args);
3. The better fix.
However, there are convenience methods such as query (yuo used the update convenience method), that are considered better than using rawQuery where possible.
The convenience methods build the underlying SQL. As such the recommended way would be to use :-
public boolean userExistance(String emailOrPhone, String pwd)
SQLiteDatabase mydb = this.getWritableDatabase();
String whereclause = "(" + COL_3 + "=? OR " + COL_4 + "=?) AND " + COL_5 + "=?";
String[] whereargs = new String[]emailOrPhone,emailOrPhone,pwd
Cursor cursor = mydb.query(TABLE_NAME,null,whereclause,whereargs,null,null,null);
boolean rv = cusror.getCount() > 0;
cursor.close();
return rv;
- Note that this has also been altered to do away with needless and potentially dangerous code.
- The Cursor is closed, if too many Cursors are left open the App will crash, so it is bad practice to not close Cursors when done with them.
- There is no need to loop through the cursor and extract the data, as all you want to know if any rows have been returned. So the count is used to set the return value to true or false, the cursor is closed and the boolean returned.
- You may wish to have a look at SQLiteDatabase - query
Note the above is in-principle code, it has not been tested or run and may therefore contain some errors.
You should also note that you will have a similar issue with getParentLoginData as the SELECT clause is very much the same.
The cause is that as parent is not enclosed in single quotes, it is considered as an identifier (in this case a column name as you could compare against a column via it's name, hence the message).
1. The quick but not so good fix.
It appears that you have such three instances so you could change :-
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = " + emailOrPhone + " OR " + COL_4 + " = " + emailOrPhone + ") AND " + COL_5 + " = " + pwd;
to be
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = '" + emailOrPhone + "' OR " + COL_4 + " = '" + emailOrPhone + "') AND " + COL_5 + " = '" + pwd + "'";
2. A better fix, but still some potential issues (see next fix)
However, should the values to compare against be via user input. This leaves the App open to SQL Injection (entering damaging commands via input), as such it is suggested that you utilise the 2nd parameter of rawQuewry method to pass a String array of values that will on a one per basis replace ?'s in the query.
As such it would be considered a safer practice to use :-
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = ? OR " + COL_4 + " =?) AND " + COL_5 + " =? ";
String[] args = new String[]emailOrPhone,emailOrPhone,pwd;
SQLiteDatabase mydb = this.getWritableDatabase();
Cursor cursor = mydb.rawQuery(sql,args);
3. The better fix.
However, there are convenience methods such as query (yuo used the update convenience method), that are considered better than using rawQuery where possible.
The convenience methods build the underlying SQL. As such the recommended way would be to use :-
public boolean userExistance(String emailOrPhone, String pwd)
SQLiteDatabase mydb = this.getWritableDatabase();
String whereclause = "(" + COL_3 + "=? OR " + COL_4 + "=?) AND " + COL_5 + "=?";
String[] whereargs = new String[]emailOrPhone,emailOrPhone,pwd
Cursor cursor = mydb.query(TABLE_NAME,null,whereclause,whereargs,null,null,null);
boolean rv = cusror.getCount() > 0;
cursor.close();
return rv;
- Note that this has also been altered to do away with needless and potentially dangerous code.
- The Cursor is closed, if too many Cursors are left open the App will crash, so it is bad practice to not close Cursors when done with them.
- There is no need to loop through the cursor and extract the data, as all you want to know if any rows have been returned. So the count is used to set the return value to true or false, the cursor is closed and the boolean returned.
- You may wish to have a look at SQLiteDatabase - query
Note the above is in-principle code, it has not been tested or run and may therefore contain some errors.
You should also note that you will have a similar issue with getParentLoginData as the SELECT clause is very much the same.
edited Mar 9 at 5:20
Halcn
878
878
answered Mar 9 at 4:41
MikeTMikeT
18.6k112844
18.6k112844
add a comment |
add a comment |
I think you need to add one (') before and after emailOrPhone
because it's a character type. and the query would be like:
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = '" + emailOrPhone + "' OR " + COL_4 + " = '" + emailOrPhone + "') AND " + COL_5 + " = " + pwd;
for more information you can check this problem: sqlite returned: error code = 1, msg = no such column:kitchen1
add a comment |
I think you need to add one (') before and after emailOrPhone
because it's a character type. and the query would be like:
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = '" + emailOrPhone + "' OR " + COL_4 + " = '" + emailOrPhone + "') AND " + COL_5 + " = " + pwd;
for more information you can check this problem: sqlite returned: error code = 1, msg = no such column:kitchen1
add a comment |
I think you need to add one (') before and after emailOrPhone
because it's a character type. and the query would be like:
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = '" + emailOrPhone + "' OR " + COL_4 + " = '" + emailOrPhone + "') AND " + COL_5 + " = " + pwd;
for more information you can check this problem: sqlite returned: error code = 1, msg = no such column:kitchen1
I think you need to add one (') before and after emailOrPhone
because it's a character type. and the query would be like:
String sql = "select * from " + TABLE_NAME + " where (" + COL_3 + " = '" + emailOrPhone + "' OR " + COL_4 + " = '" + emailOrPhone + "') AND " + COL_5 + " = " + pwd;
for more information you can check this problem: sqlite returned: error code = 1, msg = no such column:kitchen1
answered Mar 9 at 3:41
Mahdi NBAMahdi NBA
187
187
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073697%2fhaving-error-on-user-when-login-and-he-is-not-on-database%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown