private void doQuery() 

Bool hasWhere = false; 
StringBuilder sql = new StringBuilder(" SELECT * FROM T_Employee"); 
if(工号复选框选中) 

hasWhere = appendWhereIfNeed(sql, hasWhere);
sql.appendLine("FNumber BETWEEN '"+工号文本框1内容+"' AND '"+工号文本框2内容+"'"); 

if(姓名复选框选中) 

hasWhere = appendWhereIfNeed(sql, hasWhere); 
sql.appendLine("FName LIKE '%"+姓名文本框内容+"%'"); 

if(年龄复选框选中) 

hasWhere = appendWhereIfNeed(sql, hasWhere); 
sql.appendLine("FAge BETWEEN "+年龄文本框1内容+" AND "+年龄文本框2内容); 

executeSQL(sql); 

private Bool appendWhereIfNeed(StringBuilder sql,Bool hasWhere) 

if(hasWhere==false) 

sql. appendLine("WHERE"); 

else 

sql. appendLine("AND"); 

}

摘自《程序员的SQL金典》。

相关文章:

  • 2022-02-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-26
  • 2021-11-06
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-17
相关资源
相似解决方案