Get data from database Android -
i have page can retrieve user data database after whole day of trying, able table column name not value inside.
this code create database
public static final string lastlogin = "lastuser"; public static final string user_id = "suser_id"; public static final string user_name = "suser_name"; public static final string user_password = "spassword"; public static final string prime_id = "id"; private static final string table_user = "create table "+ lastlogin+" (" +prime_id+" integer primary key autoincrement, " + user_id + " text, " + user_name +" text, " +user_password+" text); ";
and here function implemented user data
public cursor getuser() { string[] columns = new string[]{prime_id, user_name, user_password}; cursor cursor = sqlitedatabase.query( lastlogin, columns, null, null, null, null, prime_id +" desc"); log.d("tag", columns[1]); return cursor; }
and here code display result
mysqliteadapter = new sqliteadapter(this); mysqliteadapter.opentowrite(); cursor = mysqliteadapter.getuser(); string[] resultvalue = new string{ sqliteadapter.prime_id,sqliteadapter.user_name, sqliteadapter.user_password}; toast.maketext(this, resultvalue[0]+resultvalue[1], toast.length_long).show();
and toast result show column name not value inside, there mistake made? , want set limit 1, set it?
thanks helping me
the way try reading values completly wrong. create array
string[] resultvalue = new string[]{ sqliteadapter.prime_id, sqliteadapter.user_name, sqliteadapter.user_password};
after read values 0 , 1 array. toast works absolutly correctly becouse inside array define column names!
if want show values query way:
while(cursor.movetonext()){ integer str1 = str 1 + cursor.getinteger(1); string str2 =str2 + cursor.getstring(2); toast.maketext(this, str1 + str2, toast.length_long).show(); }
or better way receiving correct index:
cursor.getinteger( cursor.getcolumnindex(sqliteadapter.prime_id) ); cursor.getstring( cursor.getcolumnindex(sqliteadapter.user_name) );
Comments
Post a Comment