I would take advantage of java's String Formatter:
String queryFormat = "select * from table1 where col1 between %1$s and %2$s " +
"union all " +
"select * from table2 where col1 between %1$s and %2$s " +
"union all " +
"select * from table3 where col1 between %1$s and %2$s";
String query = String.format(queryFormat,"5","10");
The first argument passed to the format method is the format string. The %1$s
means to insert the 1st argument of type string ("5"), and the %2$s
means to insert the 2nd argument of type string ("10").
The query string will then contain:
select * from table1 where col1 between 5 and 10 union all select * from table2 where col1 between 5 and 10 union all select * from table3 where col1 between 5 and 10
You can read more about the Formatter class here.
Hope this helps.