private String normalize(String str){
  String rpt3="(?i)VALUES\\s*\\((.*?)\\)";
  String rpt4="(?i)in\\s*\\([^\\(^\\)]+\\)";
  String rpt5="(?i)limit\\s+\\d+\\s*$";
  String rpt6="(?i)limit\\s+\\d+\\s*,\\s*\\d+\\s*$";
  str=str.replaceAll("=\\s*\\d+","=?");
  str=str.replaceAll("=\\s*'[^']+'","=?");
  str=str.replaceAll("\\+\\s*'?\\d+'?","+?");
  str=str.replaceAll("\\-\\s*'?\\d+'?","-?");
  str=str.replaceAll(">\\s*\\d+",">?");
  str=str.replaceAll(">\\s*'[^']+'",">?");
  str=str.replaceAll(">=\\s*\\d+",">=?");
  str=str.replaceAll(">=\\s*'[^']+'",">=?");
  str=str.replaceAll("<\\s*\\d+","<?");
  str=str.replaceAll("<\\s*'[^']+'","<?");
  str=str.replaceAll("<=\\s*'?\\d+'?","<=?");
  str=str.replaceAll("<=\\s*'[^']+'","<=?");
  str=str.replaceAll("(?i)BETWEEN\\s+\\d+\\s+AND\\s+\\d+","BETWEEN ? and ?");
  str=str.replaceAll("(?i)BETWEEN\\s+'[^']+'\\s+AND\\s+'[^']+'","BETWEEN ? and ?");
  str=str.replaceAll(rpt4,"IN (?)");
  str=str.replaceAll(rpt3,"VALUES (?)");
  str=str.replaceAll(rpt5,"LIMIT ?");
  str=str.replaceAll(rpt6,"LIMIT ?, ?");
  str=replaceInlist(str);
  return str;
}

private String normalize ( String str ) { String rpt3 = "(?i)VALUES\\s*\\((.*?)\\)" ; String rpt4 = "(?i)in\\s*\\([^\\(^\\)]+\\)" ; String rpt5 = "(?i)limit\\s+\\d+\\s*$" ; String rpt6 = "(?i)limit\\s+\\d+\\s*,\\s*\\d+\\s*$" ; str = str . replaceAll ( "=\\s*\\d+" , "=?" ) ; str = str . replaceAll ( "=\\s*'[^']+'" , "=?" ) ; str = str . replaceAll ( "\\+\\s*'?\\d+'?" , "+?" ) ; str = str . replaceAll ( "\\-\\s*'?\\d+'?" , "-?" ) ; str = str . replaceAll ( ">\\s*\\d+" , ">?" ) ; str = str . replaceAll ( ">\\s*'[^']+'" , ">?" ) ; str = str . replaceAll ( ">=\\s*\\d+" , ">=?" ) ; str = str . replaceAll ( ">=\\s*'[^']+'" , ">=?" ) ; str = str . replaceAll ( "<\\s*\\d+" , "<?" ) ; str = str . replaceAll ( "<\\s*'[^']+'" , "<?" ) ; str = str . replaceAll ( "<=\\s*'?\\d+'?" , "<=?" ) ; str = str . replaceAll ( "<=\\s*'[^']+'" , "<=?" ) ; str = str . replaceAll ( "(?i)BETWEEN\\s+\\d+\\s+AND\\s+\\d+" , "BETWEEN ? and ?" ) ; str = str . replaceAll ( "(?i)BETWEEN\\s+'[^']+'\\s+AND\\s+'[^']+'" , "BETWEEN ? and ?" ) ; str = str . replaceAll ( rpt4 , "IN (?)" ) ; str = str . replaceAll ( rpt3 , "VALUES (?)" ) ; str = str . replaceAll ( rpt5 , "LIMIT ?" ) ; str = str . replaceAll ( rpt6 , "LIMIT ?, ?" ) ; str = replaceInlist ( str ) ; return str ; }
normalize a query string
