Android.database.sqlite.SQLiteException: no such column

when I execute this query, I get 'android.database.sqlite.SQLiteException: there is 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 
+6
source share
4 answers

For string data types, always use quotation marks similar to this '"+ rid +"' " , since rid is String you get an error.

You should use + rid only if rid is int.

+24
source

you need to use apostrophe (') in the Where where statement, e.g.

 db.rawQuery("SELECT _id FROM Meeting where meet='"+rid+"'" , null); 
+16
source

You can also use this.

 db.rawQuery("SELECT _id FROM Meeting where meet=?" , new String [] {rid}); 

It will also solve the problem of SQL injection.

+5
source

Or, even better, use PreparedStatement and bind variables. This will avoid strings and dates properly for you. It will also help in SQL injections.

Are there any other people who do not know this?

+4
source

Source: https://habr.com/ru/post/946107/


All Articles