【Java开源代码栏目提醒】:网学会员为广大网友收集整理了,ClientsDAO.java,希望对大家有所帮助!
//---------------------------------------------------------
// Application: Crm of Enterprice
// Author : eSingle
// File : ClientsDAO.java
//
// Copyright 2002 LandSoft Corp.
// Generated at Sun Nov 17 23:11:00 CST 2002
// Created by 曹广鑫
// mail to 3710167@qq.com
//---------------------------------------------------------
package com.landsoft.crm.dao;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.sql.*;
import com.landsoft.crm.model.*;
import com.landsoft.crm.util.CacheManager;
public class ClientsDAO extends DAO {
public ClientsDAO(DataSource ds) {
super(ds);
}
public void insert(Clients clients) throws SQLException {
String sql;
sql = "INSERT INTO clients (clientname, sex, phone, mobile, address, http, citycode) VALUES (?, ?, ?, ?, ?, ?, ?)";
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = ds.getConnection();
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, clients.getClientname());
pstmt.setString(2, clients.getSex());
pstmt.setString(3, clients.getPhone());
pstmt.setString(4, clients.getMobile());
pstmt.setString(5, clients.getAddress());
pstmt.setString(6, clients.getHttp());
pstmt.setString(7, clients.getCitycode());
pstmt.executeUpdate();
pstmt.close();
conn.commit();
} catch (SQLException sqle) {
close(rs);
close(pstmt);
rollback(conn);
sqle.printStackTrace();
throw sqle;
} finally {
close(conn);
}
}
public void update(Clients clients) throws SQLException {
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = ds.getConnection();
String sql = "UPDATE clients SET sex=?, phone=?, mobile=?, address=?, http=?, citycode=? WHERE clientname=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, clients.getSex());
pstmt.setString(2, clients.getPhone());
pstmt.setString(3, clients.getMobile());
pstmt.setString(4, clients.getAddress());
pstmt.setString(5, clients.getHttp());
pstmt.setString(6, clients.getCitycode());
pstmt.setString(7, clients.getClientname());
pstmt.executeUpdate();
close(pstmt);
conn.commit();
} catch (SQLException e) {
close(pstmt);
rollback(conn);
e.printStackTrace();
} finally {
close(conn);
}
}
public void delete(String clientname) throws SQLException {
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = ds.getConnection();
String sql = "DELETE FROM clients WHERE clientname=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, clientname);
pstmt.executeUpdate();
close(pstmt);
conn.commit();
} catch (SQLException e) {
close(pstmt);
rollback(conn);
e.printStackTrace();
} finally {
close(conn);
}
String[] objKeys = {"Clients", String.valueOf(clientname)};
String objKey = CacheManager.createKey(objKeys);
DAOCacheManager.invalidate(objKey);
}
public Clients retrieve(String clientname) throws SQLException {
String[] objKeys = {"Clients", String.valueOf(clientname)};
String objKey = CacheManager.createKey(objKeys);
Clients clients = (Clients) DAOCacheManager.getCache(objKey);
if (clients != null)
return clients;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = ds.getConnection();
String sql = "SELECT * FROM clients WHERE clientname=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, clientname);
rs = pstmt.executeQuery();
if (rs.next()) {
clients = new Clients();
clients.setClientname(rs.getString(1));
clients.setSex(rs.getString(2));
clients.setPhone(rs.getString(3));
clients.setMobile(rs.getString(4));
clients.setAddress(rs.getString(5));
clients.setHttp(rs.getString(6));
clients.setCitycode(r