日期:2014-05-18 浏览次数:20841 次
package org.course.design.bean;
public class Customer {
private String cid; //客户编号
private String from; //查询起始日期
private String to; //查询截止日期
public Customer(String cid, String from, String to) {
super();
this.cid = cid;
this.from = from;
this.to = to;
}
public String getCid() {
return cid;
}
public void setCid(String cid) {
this.cid = cid;
}
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public String getTo() {
return to;
}
public void setTo(String to) {
this.to = to;
}
}
package org.course.design.bean;
public class Sale {
private String cid;
private String gid;
private String salesTime;
private int goodsCount;
public String getCid() {
return cid;
}
public void setCid(String cid) {
this.cid = cid;
}
public String getGid() {
return gid;
}
public void setGid(String gid) {
this.gid = gid;
}
public String getSalesTime() {
return salesTime;
}
public void setSalesTime(String salesTime) {
this.salesTime = salesTime;
}
public int getGoodsCount() {
return goodsCount;
}
public void setGoodsCount(int goodsCount) {
this.goodsCount = goodsCount;
}
}
package org.course.design.webservice;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import org.course.design.bean.Customer;
import org.course.design.bean.Sale;
public class QueryFun {
// 输入客户对象,查询数据库,返回一个销售记录集合
public List<Sale> query(Customer c){
//查询语句
String queryString = "select * from sale where cid='"+c.getCid()+"'";
//对起始日期和截止日期进行处理,仅当二者皆不为空的时候进行结合查询,否则只进行客户编号查询
if(!c.getFrom().equals("") && !c.getTo().equals("")){
queryString = queryString + " and salesTime between '" + c.getFrom()
+ "' and '" + c.getTo() + "'";
}
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
Li