public static void main(String[] args) {
String a = "a";
String b = "b";
String c = "";
StringBuffer sql = new StringBuffer();
sql.append("select * from test where ");
if ("".equals(a)) {
sql.append("a like %%");
sql.append(" and ");
} else {
sql.append("a=" + a);
sql.append(" and");
}
if ("".equals(b)) {
sql.append(" b like %%");
sql.append(" and ");
} else {
sql.append(" b=" + b);
sql.append(" and ");
}
if ("".equals(c)) {
sql.append("c like %%");
sql.append("");