I have taken String value from a EditText . And a button to submit query.
String sql=editQuery.getText().toString();// SELECT * FROM employees
StringBuffer finalDataq=new StringBuffer();
Cursor cur = dbHelper.rawsqlquery(sql);
for(cur.moveToFirst();!cur.isAfterLast();cur.moveToNext()) { finalDataq.append(cur.getInt(cur.getColumnIndex(MyDBHelper.ID)));enter code here finalDataq.append(" - "); finalDataq.append(cur.getString(cur.getColumnIndex(MyDBHelper.FIRST_NAME))); finalDataq.append(" - "); finalDataq.append(cur.getString(cur.getColumnIndex(MyDBHelper.LAST_NAME)));
finalDataq.append(" - ");
finalDataq.append(cur.getString(cur.getColumnIndex(MyDBHelper.ADDRESS)));
finalDataq.append(" - ");
finalDataq.append(cur.getDouble(cur.getColumnIndex(MyDBHelper.SALARY)));
finalDataq.append("\n");
}
submittedQuery.setText(finalDataq);
public Cursor rawsqlquery(String sql) { return myDB.rawQuery(sql,null); }
It is giving me right result . for example when i wrote select * from table_name ,it returned all row from table.
But i want to choose particular column and i dont know how to do it.I want to write my query in editext and directly want to compile and get the result it will return cursor object(if i am not wrong). Then how would i choose column name to display my result, since the columns name are written in editText. for eg: SELECT id,fname from employees
thank you in advance
Aucun commentaire:
Enregistrer un commentaire