如何在查询中的变量名称周围添加双引号?

时间:2013-10-31 13:05:52

标签: android sqlite

如何在字符串变量周围添加引号?我的数据库执行查询,如果""是变量名,我该怎么办?我做了这个"+"+ 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

1 个答案:

答案 0 :(得分: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");

只要在查询字段中使用字符串变量,就需要添加'