逃避java / sql中的双反斜杠

时间:2016-07-18 10:03:04

标签: java mysql backslash

我需要为我的the double backslash (\\)准备一个查询以查找某些特定数据,但我遇到SQL的问题,因为我可以逃避所有其余但不是这个,{{ 1}}需要四个反斜杠才能正常工作Java因为我们知道每两个反斜杠改为一个,所以我不能在行中得到四个。

任何想法都会非常有用。

这是我的方法:

public static String escapeMetaCharacters(String inputString){
    final String[] metaCharacters = {"\\","^","$","{","}","[","]","(",")",".","*","+","?","|","<",">","-","&"};
    String outputString="";
    for (int i = 0 ; i < metaCharacters.length ; i++){
        if(inputString.contains(metaCharacters[i])){
            outputString = inputString.replace(metaCharacters[i],"\\"+metaCharacters[i]);
            inputString = outputString;
        }
    }
    return outputString;
}

0 个答案:

没有答案