0

I'm working on a project where I need to set a database for users to use my application on android, for this I created two activities: One that will create a user (signUp activity) and another activity that will allow the Sign In part... My issue is, that when I compair the String value I collected from my EditText view to the Column (user_name) which content datatype is (Text) in my db, I have an error that ignores completely what comes after my select ...where ... = Here is the code, Hopefully someone knows this issue.

 name = (EditText) findViewById(R.id.user_name);
final String verify = name.getText().toString().trim();
Cursor cs = db1.rawQuery("select * from user where name_user="+verify,null);

After these instruction I used an 'If' statement that shows a toast whenever the name of the user already exists or not, I tried to surround my code with try catch, but that simply ignores the error, and in my table, we insert an empty user name... here is the error:

   android.database.sqlite.SQLiteException: near "=": syntax error (code1):while compiling: select * from user where name_user=

I know that my problem is the (verify) variable, but I don't know how to make the String value, a text value so that my sqlite command is accepted Thank you in advance for answering.

  • Note especially the [answer](https://stackoverflow.com/a/40210690/5015207) by Suragch – Bö macht Blau Apr 18 '18 at 17:18
  • How are all these posts related to my problem ? I don't see any relation, nor any solution to my problem there...sorry. – ALEXANDRA LutinNoir Apr 18 '18 at 19:53
  • Your app crashes because of an error in your query. The linked post explains how to write a query (e.g. with LIKE but also with "="). So after understanding the other post you will be able to solve your problem, with the help of a debugger if necessary. If this is not the case please edit your question to explain what you tried, what was the result etc. Then we can try to get the question reopened. – Bö macht Blau Apr 19 '18 at 04:07

1 Answers1

0
Cursor cs = db1.rawQuery("select * from user where name_user like '"+verify"'",null);

I hope this helps.

  • Thank you, it did help me, but I don't get it why the "=" didn't work, I'm trying to learn SQLite on android, and I don't understand why in this case it isn't working...Can you explain ? thank you. – ALEXANDRA LutinNoir Apr 18 '18 at 19:51
  • i think sql doesn't compare strings using equal operator but it uses like, it is same with most DBMSs – Mohamed El-shiekh Apr 20 '18 at 09:20