jsp中模糊查询

<%@ page contentType="text/html;charset=gb2312" %>
<%@ page language="java" import="java.sql.*"%>

<%
String sql = "";
String key = "";
String type= "";
String sortfield = "";
%>
<%
request.setCharacterEncoding("gb2312");
sql = "select * from student";
key = request.getParameter("mkey");
System.out.print(key);
type = request.getParameter("mtype");
sortfield = request.getParameter("sortfield");
%>


 test db connection




    查询关键字:   
 请选择查找操作字段:
    
 



 
   
     
     
     
     
   
<%
if(key != null && !key.equals("") && type != null && !type.equals(""))
    sql += " where " + type + " like '%" + key + "%' ";
if(sortfield != null && !sortfield.equals("")) 
 sql += " order by " + sortfield ;

ResultSet RS_result = connc.executeQuery( sql );
String studentName="";
String studentSex="";
String studentScore="";
String phone="";
while(RS_result.next())
{
studentName = RS_result.getString("studentid");
studentSex = RS_result.getString("studentname");
studentScore = RS_result.getString("gender");
phone=RS_result.getString("phone");
%>
   


     
     
     
 
   
<%
}
RS_result.close();
%>
 

       

    学号
  

     

       

    姓名
  

     

       

    性别
  

     

       

    电话
  

     

       
<%=studentName%>

     

       
<%=studentSex%>

     

      
<%=studentScore%>

     

      
<%=phone%>

     




值得体会

你可能感兴趣的:(JAVA专栏)