Reputation: 11948
i try to retrieve data from sqlite with this code:
String sql = "select * from "+Table +" where "+C_LoginName+"=" +user;
Log.d("CREATE DATABASE", "SQL: " + sql);
Cursor c = db.rawQuery(sql, null);
c.moveToFirst();
Log.d("Password is", c.getString(c.getColumnIndex(C_Password)));
but this error shown to me ("no such column....") i even use single quot(') side every string but not different.but when i use select * from table the loginName is there. how can solve that? tnx
Upvotes: 0
Views: 111
Reputation: 33515
no such column in sqlite android java
This kind of error is usually thrown:
Recommendation:
I don't like your approach. It's dirty, not very human-readable and very unsafe. I suggest you to use parametrized statements with placeholders where each placeholder will be replacted with value from specified array.
Example:
String query = "select * from tablename where name = ?";
db.rawQuery(query, new String[] {name}); // ? will be replaced with name value
Note:
Usually if you are dealing with database it's very good and handy practise to create some class for example called Const that will hold your column names as final static variables.
This provides more efficient and cleaner dealing with database and you'll avoid typo problems (which are too hard to find out).
Upvotes: 0
Reputation: 51721
Quotes missing around user
. Also, make sure C_LoginName
contains a valid column name.
String sql = "select * from "+Table +" where "+C_LoginName+"='" +user + "'";
Upvotes: 2