Apps keeps crashing because of syntax error - java

please help me with this problem. My app keeps crashing because of this. What I want to do is to display the user's information from the SQLite database after they login in a text view on the profile activity. Please help me with my project. I'm still new to android studio.
this is the syntax error in my logcat
android.database.sqlite.SQLiteException: near "null": syntax error (code 1 SQLITE_ERROR): , while compiling: Select * from USER_TABLE where null=?null =?null =?
This is my Database Helper
public class DatabaseHelper extends SQLiteOpenHelper {
public static String C_EMAIL,C_PREFERENCES,C_PASSWORD;;
public DatabaseHelper(#Nullable Context context) {
super(context, constants.DB_NAME, null, constants.DB_VERSION);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(constants.CREATE_TABLE);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + constants.TABLE_NAME);
onCreate(db);
}
public boolean insertInfo(String email, String preference,String password) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(constants.C_EMAIL, email);
values.put(constants.C_PREFERENCES, preference);
values.put(constants.C_PASSWORD , password);
long id = db.insert(constants.TABLE_NAME, null, values);
if (id == -1) {
return false;
}else {
return true;
}
}
public boolean userExists (String email){
String [] columns = {C_EMAIL};
SQLiteDatabase db = getReadableDatabase();
String selection = C_EMAIL + "=?";
String selectionArgs []= { email };
Cursor cursor = db.query(TABLE_NAME,columns,selection,selectionArgs,null,null,null);
int count = cursor.getCount();
cursor.close();
db.close();
if (count > 0)
return true;
else
return false;
}
public Cursor getData(String email, String Password){
SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.rawQuery(" Select * from "+ TABLE_NAME + " where "+ C_EMAIL + "=?" + C_PASSWORD + " =?", new String[]{email,Password});
return res;
}
}
This is my login.java
loginacc.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Cursor rs = dbHelper.getData(loginemail.getText().toString(),loginpassword.getText().toString());
if(rs.moveToFirst()){
String email = rs.getString(rs.getColumnIndex(DatabaseHelper.C_EMAIL));
String preference = rs.getString(rs.getColumnIndex(DatabaseHelper.C_PREFERENCES));
String password = rs.getString(rs.getColumnIndex(DatabaseHelper.C_PASSWORD));
Toast.makeText(login.this,"Login Successful", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(login.this,profile.class);
intent.putExtra("email", email);
intent.putExtra("preference", preference);
intent.putExtra("password", password);
startActivity(intent);
if(rs != null && rs.isClosed()){
rs.close();
}
}
else{
Toast.makeText(login.this,"Invalid Login", Toast.LENGTH_SHORT).show();
}
}
});
}
This is my profile.java
public class profile extends AppCompatActivity {
DatabaseHelper dbHelper;
TextView pemail,ppreferences, ppassword;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
dbHelper = new DatabaseHelper(this);
pemail = findViewById(R.id.pemail);
ppreferences = findViewById(R.id.ppreferences);
ppassword = findViewById(R.id.ppassword);
pemail.setText(getIntent().getStringExtra("email"));
ppreferences.setText(getIntent().getStringExtra("preferences"));
ppassword.setText((getIntent().getStringExtra("password")));
Thanks for your help!

You are declaring 3 static variables here:
public static String C_EMAIL,C_PREFERENCES,C_PASSWORD;
without assigning any value to them so they are all null.
When you use them inside getData():
" Select * from "+ TABLE_NAME + " where "+ C_EMAIL + "=?" + C_PASSWORD + " =?"
the result is:
Select * from USER_TABLE where null=?null =?null =?
(it's not clear from your code where the 3d null =? comes from)
What you want is (I guess) to use these variables for the column names of the table.
So change the declarations to:
public static String C_EMAIL = "email"; // change to the actual column name
public static String C_PASSWORD = "password"; // change to the actual column name
public static String C_PREFERENCES = "preferences"; // change to the actual column name
Also add the AND operator in the sql statement:
"Select * from "+ TABLE_NAME + " where "+ C_EMAIL + "= ? AND " + C_PASSWORD + " = ?"
Edit
Inside the method insertInfo() you use constants.C_EMAIL, constants.C_PREFERENCES and constants.C_PASSWORD which it seems are the names of your columns.
If so, then use them also in the sql statement and drop the static variables:
"Select * from "+ TABLE_NAME + " where "+ constants.C_EMAIL + "= ? AND " + constants.C_PASSWORD + " = ?"

Related

Data not being added to the database SQLITE

I was trying to insert data on an SQLITE database but it is not there when I open the database.
I am trying to do an application that is able to store data on a database. But when I try to add data, it doesn't get added to the table. Here's the code for the database helper and for the activity in which I call the insert data function:
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "Channels.db" ;
public static final String TABLE_NAME = "Channels_table" ;
public static final String COL_1 = "Channel_number" ;
public static final String COL_2 = "Channel_name" ;
public DatabaseHelper(Context context){
super(context, DATABASE_NAME , null , 1);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_NAME + " (Channel_number INTEGER PRIMARY KEY , Channel_name TEXT )");
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
public boolean insertData(int c_number , String c_name){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_1 , c_number);
contentValues.put(COL_2 , c_name);
long result = db.insert(TABLE_NAME , null , contentValues);
if (result == -1){
return false;
}
else
return true;
}
public class Add_Activity extends AppCompatActivity {
DatabaseHelper db;
EditText channel_name , channel_number ;
Button Add_button;
protected void onCreate (Bundle savedInstanceBundle) {
super.onCreate(savedInstanceBundle);
setContentView(R.layout.add_view);
channel_name = findViewById(R.id.channel_name_textview);
channel_number = findViewById(R.id.channel_number_textview);
Add_button = (Button) findViewById(R.id.add_button);
db = new DatabaseHelper(this);
Button_tapped();
}
public void Button_tapped(){
Add_button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(channel_name.getText().toString().isEmpty() || channel_number.getText().toString().isEmpty()){
Toast.makeText(Add_Activity.this , getText(R.string.empty_fields) , Toast.LENGTH_LONG).show();
}
else if (Integer.parseInt(channel_number.getText().toString()) < 0 || Integer.parseInt(channel_number.getText().toString()) > 84){
Toast.makeText(Add_Activity.this , getText(R.string.invalid_channel_numb) , Toast.LENGTH_LONG).show();
channel_number.setText("");
}
else {
boolean insertdata = db.insertData(Integer.parseInt(channel_number.getText().toString()) , channel_name.getText().toString());
if (insertdata){
Toast.makeText(Add_Activity.this , getText(R.string.successfull_insertion) , Toast.LENGTH_LONG).show();
}
else
Toast.makeText(Add_Activity.this , getText(R.string.unsuccessfull_insertion) , Toast.LENGTH_LONG).show();
channel_number.setText("");
channel_name.setText("");
}
}
});
}
}
When I tap the button, I get the toast for the unsuccessful insertion and the data is not being inserted into the database. What I need is to be able to see the successful insertion toast and to find the data in the database.
Try this
db.execSQL("CREATE TABLE " + TABLE_NAME + " ( " + COL_1 + " INTEGER PRIMARY KEY, " + COL_2 + " TEXT )");
instead of
db.execSQL("create table " + TABLE_NAME + " (Channel_number INTEGER PRIMARY KEY , Channel_name TEXT )");

Connecting my app to a SQLite database - how to?

I am creating a login app, where a user has an username and a password. I want to save sign up data in my database, but when I want to get access to the elements from database, no one seems to be saved ( it has no user saved in db). I suppose the error comes from db implementation. Any idea?
public class DataBaseHelper extends SQLiteOpenHelper {
public static final String TABLE_NAME = "user_table";
public static final String COL1 = "ID";
public static final String COL2 = "user_username";
public static final String COL3 = "user_password";
public DataBaseHelper(Context context) {
super(context, TABLE_NAME, null, 1);
}
#Override
public void onCreate(SQLiteDatabase db) {
String createTable = "CREATE TABLE " + TABLE_NAME + "( " + COL2 + " TEXT," +
COL3 + "TEXT)";
db.execSQL(createTable);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
public void add(String name, String password) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL2, name);
contentValues.put(COL3, password);
db.insert(TABLE_NAME, null, contentValues);
}
public Cursor getData() {
SQLiteDatabase db = this.getWritableDatabase();
String query = "SELECT *FROM " + TABLE_NAME;
Cursor data = db.rawQuery(query, null);
return data;
}
LOGIN Activity:
public void loginSeach(View view) {
EditText password_editText = (EditText) findViewById(R.id.editText_password);
EditText username_editText = (EditText) findViewById(R.id.editText_username);
String currUserName = username_editText.getText().toString();
String currPassWord = password_editText.getText().toString();
DataBaseHelper db = new DataBaseHelper(this);
Cursor data = db.getData();
int Number = 0;
while (data.moveToNext()) {
Number ++;
String userName = data.getString(1);
String passWord = data.getString(2);
}
Toast.makeText(this, Integer.toString(Number), Toast.LENGTH_SHORT).show();
}
Sign up activity:
public void createAccount(View view) {
EditText usernameEditText = (EditText) findViewById(R.id.editText_createUsername);
EditText passwordEditText = (EditText) findViewById(R.id.editText_createPassword);
String userName = usernameEditText.getText().toString();
String passWord = passwordEditText.getText().toString();
dataBaseHelper.add(userName, passWord);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
This statement in onCreate():
String createTable = "CREATE TABLE " + TABLE_NAME + "(" + COL2 + " TEXT," + COL3 + "TEXT)";
created a table without an ID column.
Uninstall the app from the emulator/device, change your code to this:
String createTable = "CREATE TABLE " + TABLE_NAME + "(" + COL1 + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COL2 + " TEXT," + COL3 + " TEXT)";
and rerun the app.

Get specific row of SQLite android

I am new to Android and I want it when the user logs in by the email and password. Bring the rest of the information like the first name and the date of birth to the user via email. Is there any way to do that?
"Is there a function I can add that can not bring all user information after logging in by email"
this is my database Code :
public class DatabaseHelper extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "UserManager.db";
private static final String TABLE_USER = "user";
private static final String COLUMN_USER_ID = "user_id";
private static final String COLUMN_USER_FIRST_NAME = "user_first_name";
private static final String COLUMN_USER_LAST_NAME = "user_last_name";
private static final String COLUMN_USER_EMAIL = "user_email";
private static final String COLUMN_USER_PHONE_NUMBER = "user_phone_number";
private static final String COLUMN_USER_BARTH_DAY = "user_barth_day";
private static final String COLUMN_USER_PASSWORD = "user_password";
private static final String COLUMN_USER_GENDER = "user_gender";
private String CREATE_USER_TABLE = "CREATE TABLE "+TABLE_USER + "("+
COLUMN_USER_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"+
COLUMN_USER_FIRST_NAME + " TEXT,"+ COLUMN_USER_LAST_NAME + " TEXT,"+
COLUMN_USER_EMAIL + " TEXT PRIMARY KEY,"+COLUMN_USER_PHONE_NUMBER + " TEXT,"+
COLUMN_USER_BARTH_DAY+" TEXT,"+ COLUMN_USER_PASSWORD+" TEXT," +
COLUMN_USER_GENDER+" TEXT"+ ")";
private String DROP_USER_TABLE = "DROP TABLE IF EXISTS "+ TABLE_USER ;
public DatabaseHelper(Context context) {
super(context , DATABASE_NAME, null , DATABASE_VERSION);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_USER_TABLE);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(DROP_USER_TABLE);
onCreate(db);
}
public void addUser(User user){
SQLiteDatabase database = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(COLUMN_USER_FIRST_NAME , user.getFirstName());
values.put(COLUMN_USER_LAST_NAME , user.getLastName());
values.put(COLUMN_USER_EMAIL , user.getEmail());
values.put(COLUMN_USER_PHONE_NUMBER , user.getPhoneNumber());
values.put(COLUMN_USER_BARTH_DAY , user.getBarthDay());
values.put(COLUMN_USER_PASSWORD , user.getPassword());
values.put(COLUMN_USER_GENDER , user.getGender());
database.insert(TABLE_USER , null, values);
database.close();
}
public boolean checkUser (String email){
String [] columns = {
COLUMN_USER_ID
};
SQLiteDatabase database = this.getWritableDatabase();
String selection = COLUMN_USER_EMAIL + " = ?";
String[] selectionArgs = {email};
Cursor cursor = database.query(TABLE_USER,
columns,selection , selectionArgs,null,null,null);
int cursorCount = cursor.getCount();
cursor.close();
database.close();
if (cursorCount > 0){
return true;
}else {
return false;
}
}
public boolean checkUser (String email , String password){
String [] columns = {
COLUMN_USER_ID
};
SQLiteDatabase database = this.getWritableDatabase();
String selection = COLUMN_USER_EMAIL + " = ?" + " AND " + COLUMN_USER_PASSWORD + " = ?";
String[] selectionArgs = {email , password};
Cursor cursor = database.query(TABLE_USER,
columns,selection , selectionArgs,null,null,null);
int cursorCount = cursor.getCount();
cursor.close();
database.close();
if (cursorCount > 0){
return true;
}else {
return false;
}
}
}
For your first question, you can add below function and use it.
public User getSingleUserInfo(String email){
SQLiteDatabase database = this.getWritableDatabase();
Cursor cursor = database.rawQuery("SELECT * FROM " + TABLE_USER + " WHERE " + COLUMN_USER_EMAIL + "=" + email);
cursor.moveToFirst();
//setting related user info in User Object
User user = new User();
user.setUserId(cursor.getInt(cursor.getColumnIndexCOLUMN_USER_ID ));
user.setFirstName(cursor.getString(cursor.getColumnIndex(COLUMN_USER_FIRST_NAME));
user.setLastName(cursor.getString(cursor.getColumnIndex(COLUMN_USER_LAST_NAME ));
user.setEmail(cursor.getString(cursor.getColumnIndex(COLUMN_USER_EMAIL ));
user.setPhoneNumber(cursor.getString(cursor.getColumnIndex(COLUMN_USER_PHONE_NUMBER ));
user.setBirthday(cursor.getString(cursor.getColumnIndex(COLUMN_USER_BARTH_DAY ));
user.setPassword(cursor.getString(cursor.getColumnIndex(COLUMN_USER_PASSWORD));
user.setGender(cursor.getString(cursor.getColumnIndex(COLUMN_USER_GENDER ));
//close cursor & database
cursor.close();
database.close();
return user;
}
Note : Becareful about your User object's setter functions which may be vary from my example and data types. Use c.getInt() if it is int and c.getString() if String.
You can use particular email address with password to query in database to get all the details.
public String getUserName(String email, String password) {
Cursor cursor = null;
String firstName = "";
try {
cursor = SQLiteDatabaseInstance_.rawQuery("SELECT * FROM " + TABLE_USER + " WHERE "+ COLUMN_USER_EMAIL +"?", new String[] {email+ ""}+ " AND "+COLUMN_USER_PASSWORD+"?", new String[] {password+ ""});
if(cursor.getCount() > 0) {
cursor.moveToFirst();
firstName= cursor.getString(cursor.getColumnIndex(COLUMN_USER_FIRST_NAME));
}
return firstName;
}finally {
cursor.close();
}
}

Searching for a row in the database doesn't work, String comparison error

I'm trying to make a register-login app in android studio and I've come across some problems in the registration part. This is my code in RegisterActivity:
public void addUser (View view) {
StringBuffer errors = new StringBuffer();
StringBuffer noerrors = new StringBuffer();
errors.append("");
noerrors.append("");
String firstname = FirstName.getText().toString();
String lastname = LastName.getText().toString();
String username = UserName.getText().toString();
String password = UserPassoword.getText().toString();
String retypepassword = RetypePassword.getText().toString();
String email = UserEmail.getText().toString();
if(!searchUsername(username)) {
errors.append("Username already exists\n");
UserName.clearComposingText();
}
if(!searchEmail(email)) {
errors.append("Email already in use\n");
UserEmail.clearComposingText();
}
if(password.equals(retypepassword)){
errors.append("Password retyped incorrectly");
UserPassoword.clearComposingText();
RetypePassword.clearComposingText();
}
userDbHelper = new UserDbHelper(context);
sqLiteDatabase = userDbHelper.getWritableDatabase();
if(errors.toString().equals(noerrors.toString())) {
userDbHelper.addInformation(firstname, lastname, username, password, email, sqLiteDatabase);
Toast.makeText(getBaseContext(), "Register successful!", Toast.LENGTH_LONG).show();
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
finish();
} else {
Toast.makeText(this, errors, Toast.LENGTH_LONG).show();
}
userDbHelper.close();
}
public boolean searchUsername(String username) {
userDbHelper = new UserDbHelper(getApplicationContext());
sqLiteDatabase = userDbHelper.getReadableDatabase();
Cursor cursor = userDbHelper.getUsername(username, sqLiteDatabase);
if(cursor.moveToFirst()) {
return true;
} else {
return false;
}
}
and this is my database helper
public class UserDbHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "USERINFO.DB";
private static final int DATABASE_VERSION = 1;
private static final String CREATE_QUERY =
"CREATE TABLE " + UserContract.NewUserInfo.TABLE_NAME + "(" + UserContract.NewUserInfo.FIRST_NAME + " TEXT," +
UserContract.NewUserInfo.LAST_NAME + " TEXT," + UserContract.NewUserInfo.USER_NAME + " TEXT," +
UserContract.NewUserInfo.USER_PASSWORD + " TEXT," + UserContract.NewUserInfo.USER_EMAIL + " TEXT);";
public UserDbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_QUERY);
}
public void addInformation (String firstname, String lastname, String username, String password, String email, SQLiteDatabase db) {
ContentValues contentValues = new ContentValues();
contentValues.put(UserContract.NewUserInfo.FIRST_NAME, firstname);
contentValues.put(UserContract.NewUserInfo.LAST_NAME, lastname);
contentValues.put(UserContract.NewUserInfo.USER_NAME, username);
contentValues.put(UserContract.NewUserInfo.USER_PASSWORD, password);
contentValues.put(UserContract.NewUserInfo.USER_EMAIL, email);
db.insert(UserContract.NewUserInfo.TABLE_NAME, null, contentValues);
Log.e("DATABASE OPERATIONS", "One row inserted");
}
public Cursor getUsername (String username, SQLiteDatabase db) {
String[] projections = {UserContract.NewUserInfo.FIRST_NAME, UserContract.NewUserInfo.LAST_NAME,
UserContract.NewUserInfo.USER_PASSWORD, UserContract.NewUserInfo.USER_EMAIL};
String selection = UserContract.NewUserInfo.USER_NAME + " LIKE ?";
String[] selection_args = {username};
Cursor cursor = db.query(UserContract.NewUserInfo.TABLE_NAME, projections, selection, selection_args, null, null, null);
return cursor;
}
}
In my registration form, whenever I retype the password correctly, my stringbuffer shows "Password retyped incorrectly" and when I retype it incorrectly, this message doesn't appear.
In the database helper, the searchEmail method is the same as searchUsername, only with a few changes so that it seaches for the email. Whether I type a username/email that is or isn't in the database, "Username already exists" and "Email already in use" are appended.
I also don't get why .clearComposingText() doesn't work to clear my edittext fields.
I found the problem. The two methods, searchEmail and searchUsername, need to take the View object as a parameter.

SQLiteLog﹕no such column

I am trying to execute a basic login form in android. This is the trimmed version of the code. Basically, if the user enters an invalid login details it should trigger an alert. However, I'm getting an error when ever I click on the Login Button.
Below posted is my code.
Alert_Dialouge alert = new Alert_Dialouge();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity);
context = this;
final DataBaseHelper hl = new DataBaseHelper(context);
AlertDialog alertDialog = new AlertDialog.Builder(
Main_activity.this).create();
Button b1 = (Button) findViewById(R.id.login);
v1 = (TextView) findViewById(R.id.TEXT_STATUS_ID);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
c = c + 1;
EditText user = (EditText) findViewById(R.id.username);
EditText pwd = (EditText) findViewById(R.id.password);
String username = user.getText().toString();
String password = pwd.getText().toString();
db = hl.getReadableDatabase();
db.beginTransaction();
String select = "SELECT * from " + " " + hl.TABLE_NAME+ " "+
"where Username = admin and Password = admin;" ;
Cursor c = db.rawQuery(select, null);
if ((username.equals("") && password.equals("")) ||
password.equals("") || username.equals("")||c.getCount()==0) {
alert.showAlertDialog(Main_activity.this, "Please enter your credentials", false);
Intent intent = new Intent(getApplicationContext(), Main_activity.class);
startActivity(intent);
finish();
} else if(c.getCount()>0) {
c.moveToFirst();
System.out.println("hiiii");
}
c.close();
}
});
}
}
Below posted is my Database Helper class
public class DataBaseHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME ="db1";
public static final int DATABASE_VERSION=8;
public static final String COLUMN_ID = "_id";
public static final String TABLE_NAME ="malware_users1";
public static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS " +"
"+ TABLE_NAME +"( _id INTEGER PRIMARY KEY AUTOINCREMENT,Username
VARCHAR(255),Password VARCHAR(255))";
public static final String DELETE_TABLE= "DROP TABLE IF EXISTS " +
TABLE_NAME;
public DataBaseHelper(Context context) {
super(context,DATABASE_NAME,null,DATABASE_VERSION);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(DELETE_TABLE);
oncreate(db);
}
public void insertData(String Username,String Password)
{
SQLiteDatabase db = this.getWritableDatabase();
db.beginTransaction();
ContentValues values;
try
{
values = new ContentValues();
values.put("Username",Username);
values.put("Password",Password);
long i =db.insert(TABLE_NAME,null,values);
Log.i("Insert",i+"");
db.setTransactionSuccessful();
}
catch (SQLiteException e)
{
e.printStackTrace();
}
finally {
db.endTransaction();
db.close();
}
}
}
Below posted is the stackTrace:
no such column: admin (code 1): , while compiling: SELECT * from
malware_users1 where Username = admin and Password = admin;
at
android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native
Method) at
android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
much better would be to use the selectionArgs argument
String select = "SELECT * from " + " " + hl.TABLE_NAME+ " "+
"where Username = ? and Password = ? ";
Cursor c = db.rawQuery(select, new String[] {"admin", "admin});
Here you can find the documentation
Please check the query which I had changed
String select = "SELECT * from " + " " + hl.TABLE_NAME+ " "+
"where Username = 'admin' and Password = 'admin'" ;
Please check it and let me know its solved the issue or not ?
in your b1 clicklistener the problem is with your select query
change this
String select = "SELECT * from " + " " + hl.TABLE_NAME+ " "+
"where Username = admin and Password = admin;" ;
to
String username="admin";
String password="admin";
String select = "SELECT * from " + hl.TABLE_NAME+
" where Username ='"+username+"' and Password ='"+password+"'" ;

Categories