-1

Hello I Got This Error: android.database.sqlite.SQLiteException: near "+" syntax error (code 1) , while compiling: SELECT * FROM tbl_Individual_Donor_Registration WHERE BloodGroup = B+

Here Is My Code For Table Elements:

public static final int DATABASE_VERSION = 3;
public static final String DATABASE_NAME = "BLOOD_PROJECT";
public static final String TABLE_NAME = "tbl_Individual_Donor_Registration";
public static final String TABLE_NAME_BLOOD_BANK = "tbl_Blood_Bank_Registration";
public static final String COL_1 = "Id";
public static final String COL_2 = "Name";
public static final String COL_3 = "Password";
public static final String COL_4 = "BloodGroup";
public static final String COL_5 = "BloodQuantity";
public static final String COL_6 = "MobileNo";

Here Is Code For My Actual Select Query:

    String select = "SELECT * FROM " + TABLE_NAME + " WHERE " + COL_4 + " = "+ final_blood_group; 

And The final_blood_group is Come From The Spinner Value which is came from the user's Selection i hope you will Help me Thank You.

t Patel
  • 1
  • 1

1 Answers1

0

You need change little thing in code.Sample here

correct code should like this

   SELECT * FROM tbl_Individual_Donor_Registration WHERE BloodGroup = 'B+'//you need single quote in B+

so you need to put single quote in

final_blood_group="'B+'";

then your code look like this

SELECT * FROM tbl_Individual_Donor_Registration WHERE BloodGroup = 'B+'

if you put without single then work as keyowrd.

ashok
  • 431
  • 5
  • 8
  • Hello You Cannot Understand My Problem the B+ is Came Dynamically And You Will Provide The Static Solution Please Provide Me Dynamic Solution Thank You. – t Patel Mar 07 '20 at 05:13
  • String select = "SELECT * FROM " + TABLE_NAME + " WHERE " + COL_4 + " = "+ " '" + final_blood_group + "' " ; – ashok Mar 07 '20 at 05:18
  • copy this line and try it – ashok Mar 07 '20 at 05:18
  • in this line i used single quote. – ashok Mar 07 '20 at 05:23
  • i just tried but it will show me Error: android.database.sqlite.SQLiteException: unrecognized token: "'" (code 1): , while compiling: SELECT * FROM tbl_Individual_Donor_Registration WHERE BloodGroup = B+' – t Patel Mar 07 '20 at 05:25
  • String select = "SELECT * FROM " + TABLE_NAME + " WHERE " + COL_4 + " = ' "+ final_blood_group + " ' " ; – ashok Mar 07 '20 at 05:35
  • above code I have not used space .this code may work. – ashok Mar 07 '20 at 05:36
  • In first solution you can see last single quote has but error at first single quote. – ashok Mar 07 '20 at 05:37
  • now I am working other things, so I cant check .else I rectify manually. – ashok Mar 07 '20 at 05:38