opendata.jsp_____________
<%
Class.forName("org.gjt.mm.mysql.Driver");
String url="jdbc:mysql://localhost:3306/mydata";
Connection con=DriverManager.getConnection(url,"root","123");
Statement smt=con.createStatement();
ResultSet rs;
//int rs;
%>
counte.jsp_________________________________
<%@ page import ="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ include file="opendata.jsp"%>
<%@ page contentType="text/html;charset=GB2312"%>
<%
request.getSession(true);
int month,day,hour,today,total,select;
String time;
int sql;
String errmsg=request.getParameter("errmsg");
GregorianCalendar calendar;
calendar=new GregorianCalendar();
month=calendar.get(Calendar.MONTH)+1;
day=calendar.get(Calendar.DAY_OF_MONTH);
hour=calendar.get(Calendar.HOUR_OF_DAY);
time="m"+String.valueOf(month)+"d"+String.valueOf(day);
//sql="select * from counter where date='"+time+"'";
rs=smt.executeQuery("select * from counter where date='"+time+"'");
if(!rs.next());
{
sql="insert into counter(date,today,first,secon,third,forth,fifth,sixth) values('"+time+"',0,0,0,0,0,0,0)";
rs=smt.executeUpdate(sql);
}
//sql="select * from counter where date='"+time+"'";
rs=smt.executeQuery("select * from counter where date='"+time+"'");
today=rs.getInt(2);
out.print(today);
out.close();
select=(int)Math.floor(hour/4)+1;
//sql="select * from total";
rs=smt.executeQuery("select * from total");
total=rs.getInt(1);
if(session.isNew())
{
today++;
switch(select)
{
case 1: //sql="update counter set today="+today+",first=first+1 where date='"+time+"'";
smt.executeQuery("update counter set today="+today+",first=first+1 where date='"+time+"'");
break;
case 2: //sql="update counter set today="+today+",secon=secon+1 where date='"+time+"'";
smt.executeQuery("update counter set today="+today+",secon=secon+1 where date='"+time+"'");
break;
case 3: //sql="update counter set today="+today+",third=third+1 where date='"+time+"'";
smt.executeQuery("update counter set today="+today+",third=third+1 where date='"+time+"'");
break;
case 4: //sql="update counter set today="+today+",forth=forth+1 where date='"+time+"'";
smt.executeQuery("update counter set today="+today+",forth=forth+1 where date='"+time+"'");
break;
case 5: //sql="update counter set today="+today+",fifth=fifth+1 where date='"+time+"'";
smt.executeQuery("update counter set today="+today+",fifth=fifth+1 where date='"+time+"'");
break;
case 6: //sql="update counter set today="+today+",sixth=sixth+1 where date='"+time+"'";
smt.executeQuery("update counter set today="+today+",sixth=sixth+1 where date='"+time+"'");
break;
}
total++;
//sql="update total set total=total+1";
smt.executeQuery("update total set total=total+1");
smt.close();
con.close();
}
%>
<html>
<title>人数浏览统计</title>
<p align-center><img src=zct.jpg><br>
<%
String showcount=String.valueOf(total);
out.print("您是本站的第");
for(int i=0;i<showcount.length();i++)
out.print("<img src="+showcount.charAt(i)+".jpg>");
out.print("位上网使用者<br>");
showcount=String.valueOf(today);
out.print("您是今天的第");
for(int i=0;i<showcount.length();i++)
out.print("<img src="+showcount.charAt(i)+".jpg>");
out.print("位上网使用者");
%>
<hr>
<center>
<form action-search.jsp method=post>
<table border=0>
<tr>
<td><font color=green>查询上网人数统计:<font></td>
<td><select size=1 name=month>
<option selected>1<option>2<option>3<option>4<option>5<option>
<option>6<option>7<option>8<option>9<option>10<option>11<option>12
</select>月
</td>
<td><select size=1 name=day>
<option selected>1<option>2<option>3<option>4<option>5<option>
<option>6<option>7<option>8<option>9<option>10<option>11<option>12
<option>13<option>14<option>15<option>16<option>17<option>
<option>18<option>19<option>20<option>21<option>22<option>23<option>24
<option>25<option>26<option>27<option>28<option>29<option>
<option>30<option>31
</select> 日
</td>
<td><input type=submit name=send value=查询></td>
</tr>
<tr>
<td colspan=4 align=center>
<a href=search.jsp?month=<%=month%>&day=<%=day%>>
<font size=3>查看今日稳中有降时段流量统计</font></a></td>
</tr>
</table>
</form>
<font color=red size=4>
<%
if(errmsg!=null)
out.print(errmsg);
%>
</font>
</html>
表结构
CREATE TABLE `counter` (
`date` char(6) DEFAULT NULL,
`today` int(6) DEFAULT NULL,
`first` int(6) DEFAULT NULL,
`secon` int(6) DEFAULT NULL,
`third` int(6) DEFAULT NULL,
`forth` int(6) DEFAULT NULL,
`fifth` int(6) DEFAULT NULL,
`sixth` int(6) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=gb2312;
CREATE TABLE `total` (
`total` int(6) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=gb2312;
哪位大哥帮一帮..小弟谢谢了.
66eagle 0 Newbie Poster
masijade 1,351 Industrious Poster Team Colleague Featured Poster
66eagle 0 Newbie Poster
masijade 1,351 Industrious Poster Team Colleague Featured Poster
66eagle 0 Newbie Poster
masijade 1,351 Industrious Poster Team Colleague Featured Poster
66eagle 0 Newbie Poster
masijade 1,351 Industrious Poster Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.