java - SQLiteLog﹕ no such colum -


i trying execute basic login form in android.this trimmed version of code.basically,if user enters invalid login details should trigger alert.however,i'm getting error when ever click on login button. below posted 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 *  " + " " + hl.table_name+ " "+              "where username = admin , 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 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 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 =db.insert(table_name,null,values);         log.i("insert",i+"");         db.settransactionsuccessful();      }     catch (sqliteexception e)     {         e.printstacktrace();     }     {         db.endtransaction();         db.close();                     }                    }                   } 

below posted stacktrace:

  no such column: admin (code 1): , while compiling: select *      malware_users1 username = admin , password = admin;         @     android.database.sqlite.sqliteconnection.nativepreparestatement(native    method) @   android.database.sqlite.sqliteconnection.acquirepreparedstatement(sqliteconnection.java:889) 

much better use selectionargs argument

 string select = "select *  " + " " + hl.table_name+ " "+                                        "where username = ? , password = ? ";   cursor c = db.rawquery(select, new string[] {"admin", "admin}); 

here can find documentation


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -