How to read row/col from CursorWindow ? - android -
this function compare it....... please find error if any.i have not logged in it
public void onclick(view v) { // todo auto-generated method stub string unname=username1.gettext().tostring(); string storedpassword1=db.getdata(unname); db.open(); try { if(password.equals(storedpassword1)) { intent it=new intent("com.butterfly.bmw.adminlist"); startactivity(it); } else { toast.maketext(database.this, "user name or password not match", toast.length_long).show(); system.out.println("errorrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"); } db.close(); } catch (exception e) { toast.maketext(database.this, "does not enter in try block", toast.length_long).show(); } } });
this db class please find error this.i have not login in this
import android.content.contentvalues; import android.content.context; import android.database.cursor; import android.database.sqlexception; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteopenhelper; import android.util.log; public class editdatabase { public static final string key_username="username"; public static final string key_role="role"; public static final string key_password="password"; private static final string tag="dbaadapter"; private static final string database_name="mydatabase"; private static final string database_table="login"; private static final int database_version=1; private static final string database_create="create table "+database_table+"("+key_username+" text primary key ,"+key_password+" text not null,"+key_role+" text not null)"; private final context context; private static databasehelper dbhelper; private static sqlitedatabase db; public editdatabase(context ctx){ this.context=ctx; dbhelper=new databasehelper(context); } private static class databasehelper extends sqliteopenhelper{ databasehelper(context context){ super(context,database_name,null,database_version); } @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { // todo auto-generated method stub log.w(tag, "upgrading database version " + oldversion + " " + newversion + ", destroy old data"); db.execsql("drop table if exists contacts"); oncreate(db); } @override public void oncreate(sqlitedatabase db) { // todo auto-generated method stub db.execsql(database_create); } } public editdatabase open() throws sqlexception{ // todo auto-generated method stub db=dbhelper.getwritabledatabase(); return this; } public long insertdetails(string uname, string pass, string string) { // todo auto-generated method stub contentvalues initialvalues = new contentvalues(); initialvalues.put(key_username, uname); initialvalues.put(key_password, pass); initialvalues.put(key_role, "admin"); return db.insert(database_table, null, initialvalues); } public void close() { // todo auto-generated method stub dbhelper.close(); } public string getdata(string unname) { // todo auto-generated method stub cursor cursor = db.rawquery("select * login key_username=?", new string [] { unname.tostring() }); if(cursor.getcount()<1) // username not exist { cursor.close(); return "not exist"; } cursor.movetofirst(); string password= cursor.getstring(cursor.getcolumnindex("key_password")); cursor.close(); return password; } public long insertdetailsuser(string uname, string pass, string string) { // todo auto-generated method stub contentvalues initialvaluess = new contentvalues(); initialvaluess.put(key_username, uname); initialvaluess.put(key_password, pass); initialvaluess.put(key_role, "user"); return db.insert(database_table, null, initialvaluess); } public cursor getallcontacts() { // todo auto-generated method stub return db.query(database_table, new string[] {key_username, key_password, key_role}, null, null, null, null, null);} public boolean deletedetails(string uname) { // todo auto-generated method stub //cursor cursor=db.rawquery("select password login " + key_username + "='" + unname + "'", null); return db.delete(database_table,key_username + "='" + uname + "'", null)>0; } }
i think might you.. try data using code.. snippet code can manage yourself..
yourdatabasefile.java
public string get(string unname) { return db.rawquery("select * login key_username=?", new string [] { unname.tostring() }); }
yourcodefile.java
public void onclick(view v) { string storedpassword; string unname=username1.gettext().tostring(); db.open(); cursor cur = db.get(unname); cur.movetofirst(); if(cur.getcount() < 1 ) { storedpassword = "not exist"; } else { storedpassword = cur.getstring(cur.getcolumnindex("key_password")); } cur.close(); try { if(password.equals(storedpassword)) { intent it=new intent("com.butterfly.bmw.adminlist"); startactivity(it); } else { toast.maketext(database.this, "user name or password not match", toast.length_long).show(); system.out.println("errorrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"); } db.close(); } catch (exception e) { toast.maketext(database.this, "does not enter in try block", toast.length_long).show(); } }
Comments
Post a Comment