0

I have to insert sequential number from 1 to N in an empty column in a database. Android Studio is giving me the following error when I run my code:

Caused by: android.database.sqlite.SQLiteException: unrecognized token: ":" (code 1): , while compiling: SELECT @i:=0; UPDATE table_name SET column_one = @i:=@i+1;

My line of code:

    db.execSQL("SELECT @i:=0; UPDATE table_name SET column_one = @i:=@i+1;");

(Please note when I change MySQL statement between parenthesis the code runs and gets executed)

Source of SQL code:

Insert sequential number in MySQL

I'm new in Java, Android Studio and MySQL.

What am I missing here?

Help me to understand why MySQL @i:=@i+1 expression is not running properly in Android Studio.

Thanks in advance.

1
  • Because android doesn't have mysql from a box, there is SqLite Commented Oct 21, 2016 at 10:32

2 Answers 2

0

Because android database is using sqlite,but sqlite dose not supported “@”,if you want batch processing ,I suggest you use Java

Sign up to request clarification or add additional context in comments.

3 Comments

Do you mean to create, save and maintain database purely on Java within Android platform? And any suggestion where to start?
Thanks for help, hope I can put website info together and come up with a solution.
0

Try this .

database.execSQL("SELECT " + @i + " :=0   ;  UPDATE table_name SET column_one = " +  @i + " := " + @i "+1;");

1 Comment

Both @i outside of parenthesis are now giving me an error before even running the code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.