/**
* @param sql语句的拼接
*/
public static void test(Integer id, String name, Double comm,
Date hiredate, int mar, String job, int empno, double sal) {
String sql = null;
String select = "select ";
StringBuffer slct = new StringBuffer(select);
String where = "where 1 = 1";
StringBuffer wer = new StringBuffer(where);
Statement stmt = null;
if (id != null) {
wer.append(" and e.id = " + id);
slct.append("e.empno empno" + ",");
}
if (name != null && !name.equals("")) {
slct.append("e.ename ename,");
wer.append(" and e.ename = '" + name + "'");
}
if (comm != null) {
wer.append(" and e.comm = " + comm);
slct.append("e.comm comm" + ",");
}
if (hiredate != null) {
slct.append("e.hiredate hiredata,");
wer.append(" and e.hiredate = "+ hiredate);
}
sql = slct + " from emp " + wer;
System.out.println(sql);
}
public static void main(String[] args) {
test(1, "asd",null , null, 0, null, 0, 0);
}