0

如何在字符串变量周围添加引号?我的数据库执行查询如果""围绕变量名我该怎么办?我这样做了,"+"+ School_name+"+"但它不起作用我如何用引号添加变量名?

       Bundle bundle = this.getIntent().getExtras();
        School_name = bundle.getString("Serachvalue");



             db.selectQuery("SELECT * FROM uss_school sch LEFT JOIN uss_school_to_level sl ON  
    sch.school_id = sl.school_id LEFT JOIN uss_level l ON sl.level_id = l.level_id WHERE  
   l.title  ="+ School_name+" ORDER BY sch.name ASC");

但是数据库用引号执行wuery,

         SELECT * FROM uss_school sch LEFT JOIN uss_school_to_level sl ON sch.school_id =  
                  sl.school_id LEFT JOIN uss_level l ON sl.level_id
= l.level_id WHERE l.title = "Elementary" ORDER BY sch.name ASC
4

1 回答 1

2

尝试以下方式,

db.selectQuery("SELECT * FROM uss_school sch LEFT JOIN uss_school_to_level sl ON  
    sch.school_id = sl.school_id LEFT JOIN uss_level l ON sl.level_id = l.level_id WHERE  
   l.title  ='"+ School_name+"' ORDER BY sch.name ASC");

'每当您在查询字段中使用字符串变量时,您只需添加即可。

于 2013-10-31T13:08:21.390 回答