📄 handlecustomer.java
字号:
/*
* HandleCustomer.java
*
* Created on 2007年4月22日, 下午8:40
*By 史双月 and 陈诗昭
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package task;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import table.Customer;
import util.DBSession;
import util.PropertiesUtil;
/**
*
* @author s
*/
public class HandleCustomer {
private DBSession dbsession=new DBSession();
/** Creates a new instance of HandleCustomer */
public HandleCustomer() {
}
//查找所有的客户资料
public Vector findAll(){
PreparedStatement ps = null;
ResultSet rs = null;
Vector v=new Vector();
try {
String sql = PropertiesUtil.getSql_resource().getString("selectcustomer").trim();
ps = dbsession.DPreparedStatement(sql);
rs = ps.executeQuery();
} catch (SQLException ex) {
ex.printStackTrace();
}
try {
while(rs.next()){
Customer customer=new Customer();
customer.setCustomerID(rs.getString("CustomerID"));
customer.setCustomerName(rs.getString("CustomerName"));
customer.setOwer(rs.getString("Ower"));
customer.setMobilePhone(rs.getString("MobilePhone"));
customer.setSeller(rs.getString("Seller"));
customer.setCustomerAddress(rs.getString("CustomerAddress"));
customer.setLastDeliveryDate(rs.getDate("LastDeliveryDate"));
//System.out.println(customer.getCustomerID());
v.add(customer);
}
} catch (SQLException ex) {
ex.printStackTrace();
}
dbsession.closedALL(rs);
return v;
}
//保存客户资料
public void save(Customer customer){
PreparedStatement ps = null;
try {
String sql = PropertiesUtil.getSql_resource().getString("insertcustomer").trim();
ps = dbsession.DPreparedStatement(sql);
ps.setString(1,customer.getCustomerID());
ps.setString(2,customer.getCustomerName());
ps.setString(3,customer.getOwer());
ps.setString(4,customer.getMobilePhone());
ps.setString(5,customer.getSeller());
ps.setString(6,customer.getCustomerAddress());
ps.setDate(7,customer.getLastDeliveryDate());
ps.executeUpdate();
} catch (SQLException ex) {
ex.printStackTrace();
}
try {
ps.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
dbsession.connClose();
}
//修改客户资料
public void update(Customer customer){
PreparedStatement ps = null;
try {
String sql = PropertiesUtil.getSql_resource().getString("updatecustomer").trim();
ps = dbsession.DPreparedStatement(sql);
ps.setString(1,customer.getCustomerName());
ps.setString(2,customer.getOwer());
ps.setString(3,customer.getMobilePhone());
ps.setString(4,customer.getCustomerAddress());
ps.setString(5,customer.getCustomerID());
ps.executeUpdate();
} catch (SQLException ex) {
ex.printStackTrace();
}
try {
ps.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
dbsession.connClose();
}
//删除客户资料
public void delete(Customer customer){
PreparedStatement ps = null;
try {
String sql = PropertiesUtil.getSql_resource().getString("deletecustomer").trim();
ps = dbsession.DPreparedStatement(sql);
ps.setString(1,customer.getCustomerID());
//ps.setString(2,customer.getCustomerName());
ps.executeUpdate();
} catch (SQLException ex) {
ex.printStackTrace();
}
try {
ps.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
dbsession.connClose();
}
//可否删除客户资料
public boolean isDelete(Customer customer){
PreparedStatement ps = null;
ResultSet rs = null;
try {
String sql = PropertiesUtil.getSql_resource().getString("selcustomer").trim();
ps = dbsession.DPreparedStatement(sql);
ps.setString(1,customer.getCustomerID());
rs = ps.executeQuery();
} catch (SQLException ex) {
ex.printStackTrace();
}
try {
while(rs.next()){
if(rs.getString("LastDeliveryDate")!=null){
dbsession.closedALL(rs);
return false;
}
}
} catch (SQLException ex) {
ex.printStackTrace();
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -