<form name=find method=post action="find.jsp">
<input type=text name=t1>
<input type=text name=t2>
<input type=text name=t3>
<input type=text name=t4>
.......
<input type=submit name=sb value="提交">
</form>
find.jsp
<%
String sl="select * from 表名 where 字段一='"+request.getParameter("t1")+"',字段二='"+request.getParameter("t2")+"',字段三='"+request.getParameter("t3")+"',字段四='"+request.getParameter("t4")+"'";//....
.....%>
<input type=text name=t1>
<input type=text name=t2>
<input type=text name=t3>
<input type=text name=t4>
.......
<input type=submit name=sb value="提交">
</form>
find.jsp
<%
String sl="select * from 表名 where 字段一='"+request.getParameter("t1")+"',字段二='"+request.getParameter("t2")+"',字段三='"+request.getParameter("t3")+"',字段四='"+request.getParameter("t4")+"'";//....
.....%>
import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;0D
import java.sql.*;
import javax.servlet.ServletContext;/**功能:构造各种常用的查询语句(不含范围和区间查询,例如:in,between,>,<等)
*说明:查询中,有些字段需要采用模糊查询,有些字段需要精确查询,likeQueryList为希望采用模糊查询的字段列表;
*有些字段的组合条件也许想放大,即采用or查询,orQueryList为希望以or连接的字段列表;有时候不希望查询数据库
*中的所有字段,而只希望查询某些字段,此时为selectList;有时候form表单为了向后传递参数,而不希望某些域参与
*与SQL语句的构造,因此必须忽略,此时的ignoreList为忽略域名列表。
*注:上述各列表(除selectList必须用逗号连接外)可在一定条件那才用任意分隔符连接,条件为:不能与分割列表中的
*任意元素相同,且连接后的组合中不含原来的元素。例如:要相对man,name,height,sex,进行查询,首先分隔符不能为其中
0A *之一,但也不能为ame,因为此时“ame”与man组合会产生“name”,程序会作出错误判断。其他均可,例如“;?!等”
*,则要将其分隔开,分隔符可为多种字符串(或字符),但不能为“name”或“sex”忽略,
0A * @param request:request对象;
* @param tableName:数据库表名;
* @param orQueryList:or查询字段列表;
* @param likeQueryList:模糊查询字段列表;
* @param selectList:希望查询的字段列表,以逗号相连传入;
* @param ignoreList:希望忽略的域名列表;
* @return:成功则返回SQL语句,否则返回""。
*/
public String getQuerySQL(HttpServletRequest request, String tableName, String orQueryList, String likeQueryList, String selectList, String ignoreList)
{
if(tableName == null ||tableName.trim().equals(""))
{
return "";
}
else
{
String query_SQL = "select ";
if(selectList != null && !selectList.equals(""))
{
query_SQL += selectList + " ";
}
else
{
query_SQL += "* ";
}
query_SQL += "from " + tableName;
int attendToConstruct 3D 0;
String queryCondition 3D "";
Enumeration nameEnum = request.getParameterNames();0D
while(nameEnum.hasMoreElements())
{
String name = nameEnum.nextElement().toString();
String[] valueArray 3D request.getParameterValues(name);
String value = S.getArrayValue(valueArray, ";", true);
if(value == null || value.equals(""))
0A {
continue;
}
if(!ignoreList.equals("") && S.isContains(ignoreList, name))
{
continue;
}
attendToConstruct++;
if(!orQueryList.equals("") && S.isContains(orQueryList, name))
{
queryCondition = " or ";
}
else
{
queryCondition = " and ";
}
if(!likeQueryList.equals("") && S.isContains(likeQueryList, name))
{
if(attendToConstruct == 1)
{
query_SQL += " where " + name + " like '" + value + "' ";
}
else
{
query_SQL += queryCondition + name + " like '" + value + "' ";
}
}
else
{
if(attendToConstruct == 1)
{
query_SQL += " where " + name + "='" + value + "' ";
}
else
{
query_SQL += queryCondition + name + "='" + value + "' ";
}
}
}
return query_SQL;
}
}
================================================================CSDN 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!★ 浏览帖子速度极快![建议系统使用ie5.5以上]。 ★ 多种帖子实现界面。
★ 保存帖子到本地[html格式]★ 监视您关注帖子的回复更新。0D
★ 可以直接发贴、回复帖子★ 采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录!
★ 支持在线检测程序升级情况,可及时获得程序更新的信息。
0A
★★ 签名 ●
可以在您的每个帖子的后面自动加上一个自己设计的签名哟。Http://www.ChinaOK.net/csdn/csdn.zip
Http://www.ChinaOK.net/csdn/cs
import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;0D
import java.sql.*;
import javax.servlet.ServletContext;/**功能:构造各种常用的查询语句(不含范围和区间查询,例如:in,between,>,<等)
*说明:查询中,有些字段需要采用模糊查询,有些字段需要精确查询,likeQueryList为希望采用模糊查询的字段列表;
*有些字段的组合条件也许想放大,即采用or查询,orQueryList为希望以or连接的字段列表;有时候不希望查询数据库
*中的所有字段,而只希望查询某些字段,此时为selectList;有时候form表单为了向后传递参数,而不希望某些域参与
*与SQL语句的构造,因此必须忽略,此时的ignoreList为忽略域名列表。
*注:上述各列表(除selectList必须用逗号连接外)可在一定条件那才用任意分隔符连接,条件为:不能与分割列表中的
*任意元素相同,且连接后的组合中不含原来的元素。例如:要相对man,name,height,sex,进行查询,首先分隔符不能为其中
0A *之一,但也不能为ame,因为此时“ame”与man组合会产生“name”,程序会作出错误判断。其他均可,例如“;?!等”
*,则要将其分隔开,分隔符可为多种字符串(或字符),但不能为“name”或“sex”忽略,
0A * @param request:request对象;
* @param tableName:数据库表名;
* @param orQueryList:or查询字段列表;
* @param likeQueryList:模糊查询字段列表;
* @param selectList:希望查询的字段列表,以逗号相连传入;
* @param ignoreList:希望忽略的域名列表;
* @return:成功则返回SQL语句,否则返回""。
*/
public String getQuerySQL(HttpServletRequest request, String tableName, String orQueryList, String likeQueryList, String selectList, String ignoreList)
{
if(tableName == null ||tableName.trim().equals(""))
{
return "";
}
else
{
String query_SQL = "select ";
if(selectList != null && !selectList.equals(""))
{
query_SQL += selectList + " ";
}
else
{
query_SQL += "* ";
}
query_SQL += "from " + tableName;
int attendToConstruct 3D 0;
String queryCondition 3D "";
Enumeration nameEnum = request.getParameterNames();0D
while(nameEnum.hasMoreElements())
{
String name = nameEnum.nextElement().toString();
String[] valueArray 3D request.getParameterValues(name);
String value = S.getArrayValue(valueArray, ";", true);
if(value == null || value.equals(""))
0A {
continue;
}
if(!ignoreList.equals("") && S.isContains(ignoreList, name))
{
continue;
}
attendToConstruct++;
if(!orQueryList.equals("") && S.isContains(orQueryList, name))
{
queryCondition = " or ";
}
else
{
queryCondition = " and ";
}
if(!likeQueryList.equals("") && S.isContains(likeQueryList, name))
{
if(attendToConstruct == 1)
{
query_SQL += " where " + name + " like '" + value + "' ";
}
else
{
query_SQL += queryCondition + name + " like '" + value + "' ";
}
}
else
{
if(attendToConstruct == 1)
{
query_SQL += " where " + name + "='" + value + "' ";
}
else
{
query_SQL += queryCondition + name + "='" + value + "' ";
}
}
}
return query_SQL;
}
}注:其中的S为一个对字符串操作的class,如需要可来信索取,我得mail是[email protected]
================================================================CSDN 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!★ 浏览帖子速度极快![建议系统使用ie5.5以上]。 ★ 多种帖子实现界面。
★ 保存帖子到本地[html格式]★ 监视您关注帖子的回复更新。0D
★ 可以直接发贴、回复帖子★ 采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录!
★ 支持在线检测程序升级情况,可及时获得程序更新的信息。
0A
★★ 签名 ●
可以在您的每个帖子的后面自动加上一个自己设计的签名哟。Http://www.ChinaOK.net/csdn/csdn.zip
Http://www.ChinaOK.net/csd