在线等待,在JSP页面里查询2次数据库,各位帮小弟看一下哪里错了啊

frieblade 2004-07-27 09:34:21
我执行history.jsp时只可以执行完第一个查询语句,但是第二个查询就显示不出来,但是把第一个一个查询删了,第二个查询就可以显示出来。不知道一个JSP页面可以进行二次查询吗?如能我的代码哪里错了啊?如不能我的代码应该怎么改啊,谢谢各位

history.jsp


<%@ page contentType="text/html; charset=gb2312" %>
<%@ page language="java" %>
<%@ page import ="java.util.*,java.io.*,web.*"%>
<%@ include file="css.inc" %>
<html>
<head>
</head>
<jsp:useBean id="history" class="web.historyBean" scope="page"/>
<body>
<center>
<%
String year=request.getParameter("year");
String mouth=request.getParameter("mouth");
String day=request.getParameter("day");
String kbh=request.getParameter("kbh");
int day1=Integer.parseInt(day);
int tempCut;
String data;
if(day1>31){tempCut=6;
data=year+mouth;
}
else{tempCut=8;
data=year+mouth+day;}
String dataYear=year+"_"+mouth;
String cut=tempCut+"";
out.println(dataYear);
out.println(data);
out.println(cut);
out.println(kbh);
%>
<table width=80% border="1" bgcolor="#0099cc">
<tr bgcolor="red" bordercolor="990066">
<td>时间</td>
<td>测点</td><td>安装地点</td><td>名称</td><td>实时值</td>
<%
Collection getCdh=history.getCdhByKbh(kbh,dataYear);
Iterator it1=getCdh.iterator();
while(it1.hasNext())
{
history temp1=(history)it1.next();
String compareCdh=null;
compareCdh=temp1.getCdh();
out.println(compareCdh); //可以执行到此处,后边的就显示不出来了
Collection his=history.getAllByAll(kbh,data,dataYear,cut);
Iterator it=his.iterator();
while (it.hasNext())
{
history temp=(history)it.next();
out.print("<tr bordercolor=#990066>");
out.println(compareCdh);
if(compareCdh.equals(temp.getCdh())){
out.println("<td>"+temp.getCshu()+"</td>");
out.println("<td>"+temp.getStatuse()+"</td>");
out.println("<td>"+temp.getCdh()+"</td>");
out.println("<td>"+temp.getAzdd()+"</td>");
out.println("<td>"+temp.getCgqmc()+"</td>");
}
}
}
%>
</table>
</center>
</body>


-------------------------------------------------------------------------

historyBean.jsp


package web;

import java.sql.*;
import java.io.*;
import web.*;
import java.util.*;

public class historyBean {
private Connection con;
public historyBean() {
this.con = DataBaseConnection.getConnection();
}

public Collection getNameByKbh(String kbh) throws Exception {
String sql = null;
Collection ret = new ArrayList();
try {
sql = "SELECT Name FROM JCWL_KuangBm where kbh = '" + kbh + "'";
Statement stmt = con.createStatement();
ResultSet rst = stmt.executeQuery(sql);
while (rst.next()) {
history temp = new history();
temp.setName(rst.getString("Name"));

ret.add(temp);
temp = null;
}
}
catch (Exception ex) {
System.out.println("数据库操作错误");
}
finally {
con.close();
}
return ret;
}

public Collection getAllByAll(String kbh, String data, String dataYear,
String cut) throws Exception {
String sql = null;
Collection ret = new ArrayList();
try {
sql = "select count(*) as cshu, max(a.cdh) as cdh ,a.statuse as statuse ,max(b.azdd) as azdd ,max(b.cgqmc) as cgqmc FROM JCWL_HDATA_" +
dataYear +
" as a,jcwl_cddy as b,jcwl_kuangbm as c Where substring(sj,1," + cut +
") ='" + data + "' and a.id = b.id and a.kbh = c.kbh and a.kbh ='" +
kbh + "' GROUP BY a.statuse,a.kbh,a.cdh";
Statement stmt = con.createStatement();
ResultSet rst = stmt.executeQuery(sql);
while (rst.next()) {
history temp = new history();
temp.setCshu(rst.getString("cshu"));
temp.setCdh(rst.getString("cdh"));
temp.setStatuse(rst.getString("statuse"));
temp.setAzdd(rst.getString("azdd"));
temp.setCgqmc(rst.getString("cgqmc"));
ret.add(temp);
temp = null;
}
}
catch (Exception ex) {
System.out.println("数据库操作错误");
}
finally {
con.close();
}
return ret;
}

public Collection getCdhByKbh(String kbh, String dataYear) throws Exception {
String sql = null;
Collection ret = new ArrayList();
try {
sql = "SELECT distinct cdh FROM JCWL_HDATA_" + dataYear +
" where kbh = " + kbh + "";
Statement stmt = con.createStatement();
ResultSet rst = stmt.executeQuery(sql);
while (rst.next()) {
history temp = new history();
temp.setCdh(rst.getString("cdh"));
ret.add(temp);
temp = null;
}
}
catch (Exception ex) {
System.out.println("数据库操作错误");
}
finally {
con.close();
}
return ret;
}
}


------------------------------------------------------------------------

history.bean



package web;

import java.io.*;

public class history {
private String cdh;
private String cshu;
private String statuse;
private String azdd;
private String Name;
private String cgqmc;

public String getCdh() {
return cdh;
}

public void setCdh(String cdh) {
this.cdh = cdh.trim();
}

public String getCshu() {
return cshu;
}

public void setCshu(String cshu) {
this.cshu = cshu.trim();
}

public String getStatuse() {
return statuse;
}

public void setStatuse(String statuse) {
this.statuse = statuse.trim();
}

public String getAzdd() {
return azdd;
}

public void setAzdd(String azdd) {
this.azdd = azdd.trim();
}

public void setName(String Name) {
this.Name = Name.trim();
}

public String getName() {
return Name;
}

public void setCgqmc(String cgqmc) {
this.cgqmc = cgqmc.trim();
}

public String getCgqmc() {
return cgqmc;
}
}

...全文
130 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
liyong33 2004-07-27
  • 打赏
  • 举报
回复
so do I
stm.close();
sealwzq 2004-07-27
  • 打赏
  • 举报
回复
我的感觉也是没有关闭记录集~~~
JAVA_XS 2004-07-27
  • 打赏
  • 举报
回复
你只关闭了数据库联接,记录集也需要关闭啊!
heavyer 2004-07-27
  • 打赏
  • 举报
回复
前一个Statement 没有关闭

最简单的解决办法
<jsp:useBean id="history1" class="web.historyBean" scope="page"/>

<jsp:useBean id="history2" class="web.historyBean" scope="page"/>

用两个
j2nix 2004-07-27
  • 打赏
  • 举报
回复
请大家关注:
http://community.csdn.net/Expert/topic/3209/3209605.xml

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧