0

I tried to do a query to the android sqlite database with the following select, but it shows only error when I put it in eclipse.

stmt = "SELECT * FROM user_zones JOIN pos WHERE user_zones.zone_id = (
                CASE  
                 WHEN user_zones.type_zone_id = 'Zone' THEN pos.zone_id
                 WHEN user_zones.type_zone_id = 'Area' THEN pos.area_id
                 WHEN user_zones.type_zone_id = 'Town' THEN pos.town_id
                 WHEN user_zones.type_zone_id = 'MicroZone' THEN pos.microzone_id END) AND user_zones.user_id = '"+id_user+"'";

Has anyone any idea about what is wrong in the above syntax? Thank you

EDIT: I cannot even run the code, there are syntax errors!

Errors:cannot find symbol class CASE

unclosed character literal
cannot find symbol class 'THEN'

expected ';' ....and so on
1
  • 3
    what is the error you got...? Commented Aug 20, 2012 at 9:08

1 Answer 1

2

If that is literally what you have pasted into your Java source, then your problem is that string literals in Java can't span multiple lines. You have to split it up using a separate string literal for each line, and glue them all together with the + operator. Like this.

stmt = "SELECT * FROM user_zones JOIN pos WHERE user_zones.zone_id = (" +
       "        CASE" +
       ...

See Paste a multi-line Java String in Eclipse

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

Comments

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.