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
Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128
adrian
  • 4,574
  • 17
  • 68
  • 119

1 Answers1

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

Community
  • 1
  • 1
Graham Borland
  • 60,055
  • 21
  • 138
  • 179