•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 402,393 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,875 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 1146 | Replies: 7
•
•
Join Date: Oct 2007
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
你好我这个程序是在学一本书时的一个例子,可是怎么也不能运行..总是那个代码说"类型不匹配"
大哥们帮一帮吧.我是小鸟...
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;
哪位大哥帮一帮..小弟谢谢了.
大哥们帮一帮吧.我是小鸟...
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;
哪位大哥帮一帮..小弟谢谢了.
•
•
•
•
•
•
•
•
DaniWeb JSP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- jsp and mysql (JSP)
- how to use jsp and tomcat (JSP)
- Can't run JSP in Browser (JSP)
- Passing arguments to jsp file (Java)
- Word.doc upload using JSP (Java)
- Can't run JSP in Browser (Web Browsers)
- JSP and Oracle (JSP)
Other Threads in the JSP Forum
- Previous Thread: problem in importing package
- Next Thread: submit button on JSP



Threaded Mode