对该页面进行自提交,每个查询条件通过text控件传递,在本页中用  
  request.getParameter();方法获得,如果不为空,则附加到sql上去;如:    

 String   date   =   request.getParameter("sDate");  
  String   sql   =   "select   *   from   tbname   where   1=1";  
   
  if(date   !=   null){  
      sql   =   sql   +   "   and   tbname.date   =   '"+   date   +"'";  
  }  
   
  sql   =   sql   +   "   order   by   **";   //最后合成的句子还可以排序  

 

 

String code = request.getParameter("code");
  String name = request.getParameter("name");

  //添加查询条件
  String condition = "";

  if ((code != null) && (!code.equals("")) && (!code.equalsIgnoreCase("NULL")))
    condition = " AND CODE LIKE '%" + code + "%'";
  else
    code = "";
  if ((name != null) && (!name.equals("")) && (!name.equalsIgnoreCase("NULL")))
    condition = condition + " AND NAME LIKE '%" + name + "%'";
  else
    name = "";


  String sqlText = "";
  if (condition == "")
    sqlText = "SELECT ROWNUM RN, ID, CODE, NAME,SPEED FROM LOOP WHERE TYPECODE = 1 AND ID = -1";
  else{
   StringBuffer buf = new StringBuffer("");
   buf.append("  SELECT ROWNUM RN, ID, CODE, NAME, TYPECODE,")
      .append(" DECODE(KINDCODE,")
      .append("              1, '二纤单向通道保护环',")
      .append("              2, '二纤单向复用段保护环',")
      .append("              3, '四纤双向复用段保护环',")
      .append("              4, '二纤双向复用段保护环',")
      .append("              5, '无保护链',")
      .append("              6, 'SNCP环',")
      .append("              7, '线性复用段',")
      .append("              8, 'PDH微波') KINDCODE,")
      .append("  (SELECT PARACONTENT FROM PARAMETER  WHERE PARATYPE = 26 AND FLOATREMARK = L.SPEED) SPEED")
      .append(" FROM LOOP L WHERE TYPECODE = 1 " + condition);
    sqlText = buf.toString();
  }

 

 

 

String name = "ddd";
String sex = "bbb";
String address = "www";

StringBuffer sql = new StringBuffer("select * from user where 1 = 1 ");
boolean valid = false;

if (name != null && name.trim().length() > 0) {
sql.append(" and name like '%" + name + "%'");
valid = true;
}
if (sex != null && sex.trim().length() > 0) {
sql.append(" and sex like '%" + sex + "%'");
valid = true;
}
if (address != null && address.trim().length() > 0) {
sql.append(" and address like '%" + address + "'%");
valid = true;
}

if (valid) {

Connection con = null;
Statement stmt = null;
ResultSet rs;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:jj";

con = DriverManager.getConnection(url, "xkxk", "xkxk");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(sql.toString());

while (rs.next()) {

// 操作数据
}

}