标签:java 替换 字符串 code color 类型 字符 url 中间
实现目标语句是这个
注意,这里的java变量是idd
int idd; String sql = "SELECT id, piUrl FROM picinfos WHERE id BETWEEN ‘" + idd + "‘ AND 10" ;
java中的字符串只能双引号,如果字符串中需要拼接变量,该变量用单引号括起来,然后加两个双引号再加两个加号,中间就是变量。
//查询picinfos表中id为2到10的id和piUrl值 String sql = "SELECT id, piUrl FROM picinfos WHERE id BETWEEN 2 AND 10" ;
2.此时要将2改为id(int类型变量),只需要在中间修改
,先是删掉2,用单引‘ ‘代替
String sql = "SELECT id, piUrl FROM picinfos WHERE id BETWEEN ‘ ‘ AND 10" ;
3.接着在单引号中间加上双引" "
String sql = "SELECT id, piUrl FROM picinfos WHERE id BETWEEN ‘ " " ‘ AND 10" ;
4.接着在双引号中间加上加号+ +
String sql = "SELECT id, piUrl FROM picinfos WHERE id BETWEEN ‘ " + + " ‘ AND 10" ;
5.最后就是加号中间加上变量idd完事
String sql = "SELECT id, piUrl FROM picinfos WHERE id BETWEEN ‘ " + idd + " ‘ AND 10" ;
口诀:先SQL原型,替换为单引,中间加双引,中间加双加号,中间加变量。
标签:java 替换 字符串 code color 类型 字符 url 中间
原文地址:https://www.cnblogs.com/mike-mei/p/10206596.html