I am unable to retrieve data from database in android from sqlite without php or any -
i doing project, need retrieve data sqlite database, unable that. kindly me through out.
my login code
package com.example.pallavi.myproject; import android.app.activity; import android.content.intent; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.os.bundle; import android.text.inputtype; import android.view.view; import android.widget.edittext; import android.widget.imageview; import android.widget.toast; public class login extends activity{ intent i=null; edittext tv1,tv4; boolean flag=false; sqlitedatabase db=null; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.login); tv1 = (edittext) findviewbyid(r.id.phone2); tv4 = (edittext) findviewbyid(r.id.password2); db = openorcreatedatabase("mydb", mode_private, null); } public void action(view v) { string mobile_no=tv1.gettext().tostring(); string password=tv4.gettext().tostring(); /* if(mobile_no==null||mobile_no=="") { show("please enter correct mobile number."); } else if(password==null||password=="") { show("please enter correct password."); } else*/ { show("query not executing"); string[] args={"null"}; cursor c=db.rawquery("select * login mobile_no='"+mobile_no+"'",args); c.movetofirst(); show("not going inside"); if(c.getcount()>0) { show("success login"); i=new intent(this,post.class); db.close(); finish(); } else show("wrong password or mobile number."); } } public void acc(view v) { if (v.getid()==r.id.button) { intent i=new intent(login.this,mainactivity.class); startactivity(i); } } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { } public void show(string str) { toast.maketext(this, str, toast.length_long).show(); } }
kindly check through it. trying retrieve data db , check, not performing operation.
if want retrieve data sqlite log in use code:
public void login_user(view view) { edittextusername = (edittext) findviewbyid(r.id.edittext2); edittextid = (edittext) findviewbyid(r.id.edittext); edittextid.setfocusable(true); username = edittextusername.gettext().tostring(); password = edittextid.gettext().tostring(); final string idd = password; final string name = username; if (password.equals("")) { edittextid.seterror("enter user id"); edittextid.requestfocus(); } else if (username.equals("")) { edittextusername.seterror("enter user name"); edittextusername.requestfocus(); } else { string storedpassword = databasehelper.getsinuserlgeentry(username,password); // check if stored password matches password entered user if (password.equals(storedpassword)) { toast toast = toast.maketext(this, "congrats: login successful", toast.length_long); view vieew = toast.getview(); // vieew.setbackgroundcolor(color.parsecolor("#bd8bdc")); vieew.setbackgroundresource(r.drawable.textinputborder); toast.setview(vieew); // textview text = (textview) view.findviewbyid(android.r.id.message); /*here can text*/ toast.show(); intent intent = new intent(this, user_home.class); intent.putextra("name", username); intent.putextra("id", password); startactivity(intent); } else { toast toast = toast.maketext(this, "user name or password not match", toast.length_long); view vieew = toast.getview(); // vieew.setbackgroundcolor(color.parsecolor("#bd8bdc")); vieew.setbackgroundresource(r.drawable.textinputborder); toast.setview(vieew); // textview text = (textview) view.findviewbyid(android.r.id.message); /*here can text*/ toast.show(); } edittextusername.settext(""); edittextid.settext(""); edittextid.requestfocus(); } }
finally use in sqlite database class :
public string getsinuserlgeentry(string username, string id) { sqlitedatabase db = this.getwritabledatabase(); // cursor cursor = db.query("day_info", null, " emp_name=?", new string[]{username}, null, null, null); cursor cursor = db.query(table_name, null, emp_name + " '%" + username + "%' , " + main_idd + " '%" + id + "%'", null, null, null, null); if (cursor.getcount() < 1) // username not exist { cursor.close(); return "not exist"; } cursor.movetofirst(); string iddd = cursor.getstring(cursor.getcolumnindex("mid")); cursor.close(); return iddd; }
Comments
Post a Comment