For dynamic query
generate by hibernate contains ? marks , to run that query in SQL is
difficult.
So this code
replace question marks with corresponding binding values.
public class test { public static void main(String[] args) { File queryFile = new File("D:/a.txt");//file a conatin Query File valuesFile = new File("D:/b.txt"); //file b conatain binding values int ch; StringBuffer queryContent = new StringBuffer(""); StringBuffer valuesContent = new StringBuffer(""); FileInputStream queryFin = null; FileInputStream valueFin = null; try { queryFin = new FileInputStream(queryFile); while ((ch = queryFin.read()) != -1) queryContent.append((char) ch); queryFin.close(); valueFin = new FileInputStream(valuesFile); while ((ch = valueFin.read()) != -1) valuesContent.append((char) ch); valueFin.close(); int startIndex = 0; while (queryContent.indexOf("?") > 0) { int index1 = queryContent.indexOf("?"); int index2 = valuesContent.indexOf("binding '", startIndex); if(index2<0){ System.out.println("number of question marks and binding data not equal"); return; } int index3 = valuesContent.indexOf("'", index2 + 9); String rep = valuesContent.substring(index2 + 9, index3); queryContent.replace(index1, index1 + 1, rep); startIndex = index3; } FileWriter fstream = new FileWriter("D:/out.txt");//output file BufferedWriter out = new BufferedWriter(fstream); out.write(queryContent.toString()); out.close(); } catch (Exception e) { System.out.println(e); } System.out.println(queryContent.toString()); } }