Wednesday, 15 May 2013

java - Unable to retrieve data from SQLite -



java - Unable to retrieve data from SQLite -

please have @ next code

databasehandler.java

the code used retrieve data

public list<string> getallbranches() { // todo auto-generated method stub string selectquery = "select city branchnetwork"; cursor cursor = database.rawquery(selectquery, null); list <string>branches = new arraylist<string>(); if(cursor.isfirst()) { { } while(cursor.movetonext()); toast.maketext(context, "data retrieved: "+branches.get(1), toast.length_long).show(); } homecoming branches; }

the code used insert data

public string insertdata(string city, string streetaddress,string phonenumber1, string phonenumber2, string email) { string insertquery = "insert branchnetwork ('city','streetaddress','phonenumber1','phonenumber2','email') values('"+city+"','"+streetaddress+"','"+phonenumber1+"','"+phonenumber2+"','"+email+"');"; seek { database.execsql(insertquery); homecoming "data inserted"; } catch(exception e) { toast.maketext(context, "exception: "+e.getmessage(), toast.length_long).show(); homecoming "data insertion failed"; } }

form.java

the first activity. here retrieve info , insert data. next how retrieve data

public class form extends activity { private list<string>branches = new arraylist<string>(); private databaseconnector databaseconnector; string[]arr; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_form); databaseconnector = databasehandler.getinstance(this); databaseconnector.createconnection(); branches = databaseconnector.getallbranches(); arr = branches.toarray(new string[branches.size()]); } }

but, never anything! in databasehandler.java, have made toast should generate message when code retrieved. not generating anything! loading info listview empty! why this? please help!

ps: next databaseconnector.java, insert face databasehandler

package com.example.esoftcallmanager; import java.util.list; import android.content.context; public interface databaseconnector { public void createconnection(); public void closeconnection(); public string getphonenumber(); public string insertdata(string city, string streetaddress, string phonenumber1, string phonenumber2, string email); public list<string>getallbranches(); }

you forget add together info in array of list. seek out below:

string selectquery = "select city branchnetwork"; cursor cursor = database.rawquery(selectquery, null); list <string> branches = new arraylist<string>(); string str=null; cursor.movetofirst(); { str= m_cursor.getstring(m_cursor.getcolumnindex("city")); branches.add(str); } while(cursor.movetonext()); toast.maketext(context, "data retrieved: "+branches.get(1), toast.length_long).show(); } homecoming branches;

java android eclipse sqlite

No comments:

Post a Comment