when i execute this query i get ‘android.database.sqlite.SQLiteException: no such column’ what is the error?
public Cursor Getupdate(String rid) throws SQLException
{
Cursor m1Cursor = db.rawQuery("SELECT _id FROM Meeting where meet="+rid , null);
if (m1Cursor != null) {
if(m1Cursor.getCount() > 0)
{
m1Cursor.moveToFirst();
}
}
return m1Cursor;
}
logcat
05-28 01:22:27.999: E/AndroidRuntime(1411): FATAL EXCEPTION: main
05-28 01:22:27.999: E/AndroidRuntime(1411): android.database.sqlite.SQLiteException: no such column: ttyuhomk: , while compiling: SELECT _id FROM Meeting where meet=rage
For string data type always use quotes like this ‘”+rid+”‘” since rid is String you get error.
You should use +rid only if rid is int.
Answer:
you need to use apostrophe(‘) in Where clause checking.. like
db.rawQuery("SELECT _id FROM Meeting where meet='"+rid+"'" , null);
Answer:
You can also use like this.
db.rawQuery("SELECT _id FROM Meeting where meet=?" ,
new String [] {rid});
This will also solve for SQL injection problem.
Answer:
Or, better yet, use a PreparedStatement and bind your variables. It’ll escape strings and dates properly for you. It’ll also help with SQL injection problems.
Are there still people who don’t know about this?