Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器

首页 / 操作系统 / Linux / Java中使用SQL的效率分析例子

前年给地图技术审查中心做了一个培训的报名系统,功能需求比较简单,由于当时刚开始摸索java就只能照葫芦画瓢的使用JDBC写的程序。这是中百信公司的遗留项目,我接手过来的,仿照以前的代码写得。出现问题的代码:
  1. <div id="content">  
  2.             <div class="locbackground">  
  3.             </div>  
  4.             <div class="text">  
  5.             <center>  
  6.                 <h1>  
  7.                     查看培训(会议)报名信息  
  8.                 </h1>  
  9.                 <div><input type="button" value="导出会议(培训)报名信息 " onclick="location.href="/dtsc/pxbm/outRegisterByConference.jsp?cid=<%=request.getParameter("cid")%>""/></div>  
  10.                 <br/><table class="listCases" width="100%" border="0"  
  11.                     style="width: 100%; FONT-SIZE: 18px; word-break: break-all"  
  12.                     cellspacing="1" cellpadding="5" bgcolor=#455ca2>  
  13.                     <thead>  
  14.                         <tr height="40px">  
  15.                             <th width="70" bgcolor=#dcdcdc align="center" class=""  
  16.                                 style="font-size: 14px; FONT-WEIGHT: bold">  
  17.                                 操作  
  18.                             </th>  
  19.                             <th width="30" bgcolor=#dcdcdc align="center" class=""  
  20.                                 style="font-size: 14px; FONT-WEIGHT: bold">  
  21.                                 序号  
  22.                             </th>  
  23.                             <th width="30" bgcolor=#dcdcdc align="center" class=""  
  24.                                 style="font-size: 14px; FONT-WEIGHT: bold">  
  25.                                 姓名  
  26.                             </th>  
  27.                             <th bgcolor=#dcdcdc align="center" class=""  
  28.                                 style="font-size: 14px; FONT-WEIGHT: bold">  
  29.                                 性别  
  30.                             </th>  
  31.                             <th bgcolor=#dcdcdc align="center" class=""  
  32.                                 style="font-size: 14px; FONT-WEIGHT: bold">  
  33.                                 民族  
  34.                             </th>  
  35.                             <th bgcolor=#dcdcdc align="center" class=""  
  36.                                 style="font-size: 14px; FONT-WEIGHT: bold">  
  37.                                 身份证号  
  38.                             </th>  
  39.                             <th bgcolor=#dcdcdc align="center" class=""  
  40.                                 style="font-size: 14px; FONT-WEIGHT: bold">  
  41.                                 工作单位  
  42.                             </th>  
  43.                             <th bgcolor=#dcdcdc align="center" class=""  
  44.                                 style="font-size: 14px; FONT-WEIGHT: bold">  
  45.                                 职务(职称)  
  46.                             </th>  
  47.                             <th bgcolor=#dcdcdc align="center" class=""  
  48.                                 style="font-size: 14px; FONT-WEIGHT: bold">  
  49.                                 手机号码  
  50.                             </th>  
  51.                             <th bgcolor=#dcdcdc align="center" class=""  
  52.                                 style="font-size: 14px; FONT-WEIGHT: bold">  
  53.                                 乘坐何种 交通工具(班次)  
  54.                             </th>  
  55.                             <th bgcolor=#dcdcdc align="center" class=""  
  56.                                 style="font-size: 14px; FONT-WEIGHT: bold">  
  57.                                 到达时间  
  58.                             </th>  
  59.                             <th bgcolor=#dcdcdc align="center" class=""  
  60.                                 style="font-size: 14px; FONT-WEIGHT: bold">  
  61.                                 注册时间  
  62.                             </th>  
  63.                             <th bgcolor=#dcdcdc align="center" class=""  
  64.                                 style="font-size: 14px; FONT-WEIGHT: bold">  
  65.                                 ip地址  
  66.                             </th>  
  67.                         </tr>  
  68.                     </thead>  
  69.                     <%  
  70.                         Collection registerId = conferenceRegisterAssignOp.getRegisterIdByConferenceId(Integer.parseInt(request.getParameter("cid")));  
  71.                         Iterator it = registerId.iterator();  
  72.                         int index = 1;  
  73.                         while (it.hasNext()) {  
  74.                             Integer integer = (Integer)it.next();  
  75.                             int rid = integer.intValue();  
  76.                             Register temp = registerOp.getCaseInfo(rid);  
  77.                     %>  
  78.                     <tr>  
  79.                         <td class="listContent">  
  80.                             <a href="dtsc/pxbm/editRegister.jsp?registerId=<%=temp.getId()%>">编辑</a>  
  81.                             <br />  
  82.                             <br />  
  83.                             <a href="dtsc/pxbm/deleteRegister.jsp?registerId=<%=temp.getId()%>">删除</a>  
  84.                             <br />  
  85.                             <br />  
  86.                             <a href="dtsc/pxbm/editRegister.jsp?registerId=<%=temp.getId()%>">查看详细</a>  
  87.                         </td>  
  88.                         <td class="listContent"><%=index%></td>  
  89.                         <td class="listContent"><%=temp.getName() %></td>  
  90.                         <td class="listContent"><%=CodeSet.getSex(temp.getSex())%></td>  
  91.                         <td class="listContent"><%=temp.getRace()%></td>  
  92.                         <td class="listContent"><%=temp.getIdentificationId() %></td>  
  93.                         <td class="listContent"><%=temp.getDepartment()%></td>  
  94.                         <td class="listContent"><%=temp.getPositionOrIdentity()%></td>  
  95.                         <td class="listContent"><%=temp.getMobilephone()%></td>  
  96.                         <td class="listContent"><%=temp.getDeparture()%></td>  
  97.                         <td class="listContent"><%=temp.getArrivingTime()%></td>  
  98.                         <td class="listContent"><%=temp.getRegisterTime()%></td>  
  99.                         <td class="listContent"><%=temp.getIp()%></td>  
  100.                     </tr>  
  101.                     <%  
  102.                         ++index;  
  103.                         }  
  104.                     %>  
  105.                 </table>  
  106.                 </center>  
  107.             </div>  
  108.         </div>  
因为是嵌在JSP页面的中代码,在java代码后面跟的是一些显示用的HTML代码。注意这一段代码:
  1. Collection registerId = conferenceRegisterAssignOp.getRegisterIdByConferenceId(Integer.parseInt(request.getParameter("cid")));  
  2.                     Iterator it = registerId.iterator();  
  3.                     int index = 1;  
  4.                     while (it.hasNext()) {  
  5.                         Integer integer = (Integer)it.next();  
  6.                         int rid = integer.intValue();  
  7.                         Register temp = registerOp.getCaseInfo(rid);  
这里边先根据cid(培训会议表id)取到了参加本次会议的注册人员的id列表。
  1. Collection registerId = conferenceRegisterAssignOp.getRegisterIdByConferenceId(Integer.parseInt(request.getParameter("cid")));  
然后再遍历这个列表,对每一个注册人员id,都取出这个人员的详细信息。
  1. Register temp = registerOp.getCaseInfo(rid);  
这样在报名的数量达到200条的时候运行起来的时间大约为40s到70秒s。由于这个页面的table中的行tr是在后台逐条生成的,再Collection遍历是陆陆续续发送到浏览器的,这样会使浏览器等待页面的时间太长,导致浏览器与后台Web Server的连接超过TimeOut时长,断开连接。反应到前端浏览器的现象就是页面的前半部分加载完成,列表没有全部加载出来。