📄 listuser.jsp
字号:
<%-- listUser.jsp程序代码 --%>
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.util.Calendar" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%
//取得查询条件值
request.setCharacterEncoding("gb2312");
String username=request.getParameter("username");
String region=request.getParameter("region");
int months=Integer.parseInt(request.getParameter("months"));
//
Calendar nowCalendar=Calendar.getInstance();
String nowDate=nowCalendar.get(Calendar.YEAR)+"/"+
(nowCalendar.get(Calendar.MONTH)+1)+"/"+
nowCalendar.get(Calendar.DATE);
nowCalendar.add(Calendar.MONTH,-months);
String beforeDate=nowCalendar.get(Calendar.YEAR)+"/"+
(nowCalendar.get(Calendar.MONTH)+1)+"/"+
nowCalendar.get(Calendar.DATE);
//out.println(nowDate+" "+beforeDate);
//建立数据库连接并执行数据查询
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:datasource_suit","sa","710318");
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String strSQL="select username,sex,age,region,email,marriage,regdate from t_userInfo where ";
strSQL+="username like '%"+username+"%' and ";
strSQL+="region='"+region+"' and ";
strSQL+="regdate>='"+beforeDate+"' and regdate<='"+nowDate+"' order by regdate desc";
//out.println(strSQL);
rs=stmt.executeQuery(strSQL);
%>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>会员查询</title>
</head>
<body>
<p align="center"><u><b><font face="仿宋_GB2312" size="3" color="#0000FF">会 员 资 料 表</b></u></p></font>
<div align="center">
<center>
<table border="0" width="100%" height="25">
<tr>
<td width="118" height="1" bgcolor="#EAF4F4" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF">姓名</font></td>
<td width="81" height="1" bgcolor="#EAF4F4" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF">性别</font></td>
<td width="166" height="1" bgcolor="#EAF4F4" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF">年龄</font></td>
<td width="95" height="1" bgcolor="#EAF4F4" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF">地区</font></td>
<td width="185" height="1" bgcolor="#EAF4F4" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF">email</font></td>
<td width="80" height="1" bgcolor="#EAF4F4" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF">婚姻</font></td>
<td width="162" height="1" bgcolor="#EAF4F4" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF">入会日期</font></td>
</tr>
<%
while(rs.next()){
%>
<tr>
<td width="118" height="1" bgcolor="#FFD9FF" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF"><%=rs.getString("username")%></font></td>
<td width="81" height="1" bgcolor="#FFD9FF" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF"><%if(rs.getInt("sex")==1){out.print("男");}else{out.print("女");}%></font></td>
<td width="166" height="1" bgcolor="#FFD9FF" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF"><%=rs.getString("age")%></font></td>
<td width="95" height="1" bgcolor="#FFD9FF" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF"><%=rs.getString("region")%></font></td>
<td width="185" height="1" bgcolor="#FFD9FF" align="center"><font face="Arial" size="3" color="#0000FF"><%=rs.getString("email")%></font></td>
<td width="80" height="1" bgcolor="#FFD9FF" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF"><%if(rs.getInt("marriage")==1){out.print("已婚");}else{out.print("未婚");}%></font></td>
<td width="162" height="1" bgcolor="#FFD9FF" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF"><%=rs.getDate("regdate")%></font></td>
</tr>
<%
} //while循环的结束符
}catch(Exception e){
out.println("查询失败.");
}
finally{
try{
if(rs!=null){
rs.close();
}
if(stmt!=null){
stmt.close();
}
if(conn!=null){
conn.close();
}
}catch(SQLException sqle){}
}
%>
</table>
</center>
</div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -