请教高手们!

edsonwen 2005-01-28 08:45:15
JAVA代码:
package phoneproject;

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

public class RigorSearchBean extends WeblogicContext implements Serializable {
private static String companyName;
private static String relationMan;
private static String phone;
private static String email;
private static String mailNO;
private static String type;
private static String web;
private static String address;
private static String remark;
private static String data;
private static String check=null;
static Statement stat=null;
static ResultSet result=null;

public static Vector QueryData(){
Vector v=new Vector();
try{
String sql="";
stat=getConnection().createStatement();
if(check.equals("companyName")){
sql="select RelationMan,Phone,Email,Web,Address,MailNO,Remark from CompanyInfo where companyName like '%"+data+"%'";
}
result=stat.executeQuery(sql);
while(result.next()){
RigorSearchBean temp=new RigorSearchBean();
temp.setRelationMan(result.getString("relationMan"));
temp.setPhone(result.getString("phone"));
temp.setEmail(result.getString("email"));
temp.setWeb(result.getString("web"));
temp.setAddress(result.getString("address"));
temp.setMailNO(result.getString("mailNO"));
temp.setRemark(result.getString("remark"));
v.add(temp);
}
}
catch(Exception e){
System.out.println("a"+e.getMessage());
}
return v;
}
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
ois.defaultReadObject();
}
private void writeObject(ObjectOutputStream oos) throws IOException {
oos.defaultWriteObject();
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public String getRelationMan() {
return relationMan;
}
public void setRelationMan(String relationMan) {
this.relationMan = relationMan;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getMailNO() {
return mailNO;
}
public void setMailNO(String mailNO) {
this.mailNO = mailNO;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getWeb() {
return web;
}
public void setWeb(String web) {
this.web = web;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public String getCheck() {
return check;
}
public void setCheck(String check) {
this.check = check;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
}

JSP代码:
<%@ page contentType="text/html; charset=GBK" %>
<%@ page errorPage="RigorSearchResult_error.jsp" %>
<html>
<head>
<title>
RigorSearchResult
</title>
</head>
<jsp:useBean id="rigorsearch" scope="session" class="phoneproject.RigorSearchBean" />
<jsp:setProperty name="rigorsearch" property="*" />
<body bgcolor="#ffffff">
<h1>
JBuilder Generated JSP
</h1>
<table border="2">
<tr>
<th>联系姓名</th>
<th>联系电话</th>
<th>信箱</th>
<th>网址</th>
<th>地址</th>
<th>邮编</th>
<th>简介</th>
</tr>
<%
Vector v=(phoneproject.RigorSearchBean).QueryData();
for(int i=0;i<v.size();i++){
phoneproject.RigorSearchBean temp=(phoneproject.RigorSearchBean)v.elementAt(i);
%>
<tr>
<td><%=temp.getRelationMan()%></td>
<td><%=temp.getPhone()%></td>
<td><%=temp.getEmail()%></td>
<td><%=temp.getWeb()%></td>
<td><%=temp.getAddress()%></td>
<td><%=temp.getMailNO()%></td>
<td><%=temp.getRemark()%></td>
</tr>
<%}%>
</table>
</body>
</html>
问题是:我的数据库有两条companyName为"edson"和"edsonwen"的记录。上面的sql语句在数据库的查询分析器是查出两条不同的记录,而在我的JSP页面显示的两条记录都是最后那条记录的内容,即两条都是(edsonwen)的内容。
...全文
41 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
edsonwen 2005-01-29
  • 打赏
  • 举报
回复
怎么没有人回我呀!
little06 2005-01-29
  • 打赏
  • 举报
回复
帮你Up
别沉了

81,092

社区成员

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

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