package com.wzxy.dao;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.wzxy.exception.DBException;
import com.wzxy.exception.LoginFailedException;
import com.wzxy.exception.PetOrOwnerNotExistsException;
import com.wzxy.exception.VetNotExistsException;
import com.wzxy.exception.VisitHistoryNotExist;
import com.wzxy.pojos.EmpDTO;
import com.wzxy.pojos.Fenye;
import com.wzxy.pojos.PetDTO;
import com.wzxy.pojos.PetOwnerDTO;
import com.wzxy.pojos.PetVisitDTO;
import com.wzxy.pojos.VetDTO;
import com.wzxy.utils.DBUtils;
public class PetServiceImpl implements IPetService {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rset = null;
public EmpDTO LoginVerify(String name, String pwd)
throws LoginFailedException, DBException {
EmpDTO emp = null;
String sql = "select * from employee where name='" + name
+ "' and password='" + pwd + "'";
con = new DBUtils().getCon();
try {
pstmt = con.prepareStatement(sql);
rset = pstmt.executeQuery();
if (rset.next()) {
emp = new EmpDTO();
emp.setEmp_name(rset.getString("name"));
emp.setEmp_pwd(rset.getString("password"));
}
} catch (SQLException e) {
e.printStackTrace();
throw new DBException("database operation failed");
} finally {
new DBUtils().reaseSource(con, pstmt, rset);
}
if (emp == null) {
throw new LoginFailedException("login Failed!");
}
System.out.println("sql is " + sql);
return emp;
}
public List VetSearch(String name, String vetSpecName) throws DBException,
VetNotExistsException {
String sql = "select v.id, v.name,s.name,s.id from vets v,specialties s,vet_specialties vs "
+ " where v.name like '%"
+ name
+ "%' and v.id=vs.vet_id and vs.specialty_id=s.id "
+ " and s.name like '%"
+ vetSpecName
+ "%' and v.id=vs.vet_id and vs.specialty_id=s.id";
ArrayList list = new ArrayList();
con = new DBUtils().getCon();
try {
pstmt = con.prepareStatement(sql);
rset = pstmt.executeQuery();
while (rset.next()) {
VetDTO vet = new VetDTO();
vet.setVetId(rset.getInt(1));
vet.setVetName(rset.getString(2));
vet.setSpecName(rset.getString(3));
vet.setSpecId(rset.getInt(4));
list.add(vet);
}
} catch (SQLException e) {
e.printStackTrace();
throw new DBException("database operation failed");
}
if (list.isEmpty())
throw new VetNotExistsException("vet is not exists!");
System.out.println("sql is " + sql + " list is :" + list);
return list;
}
public List PetSearch(String petName, String ownerName, Fenye fy)
throws PetOrOwnerNotExistsException, DBException {
/*
* String sql = "select p.id, p.name as
* petName,p.birth_date,p.type_id,p.owner_id,o.name as
* ownerName,t.name,o.address,o.city,o.telephone" + " from pets p,owners
* o,types t where p.name like '%" + petName + "%' and o.name like '%" +
* ownerName + "%'" + " and p.owner_id=o.id and p.type_id=t.id";
*/
int n = fy.getShowlist();
int m = (fy.getShowpage() - 1) * n;
String sql = "select top " + n + " p.id, p.name ,p.owner_id,o.name "
+ " from pets p,owners o where p.name like '%" + petName
+ "%' and o.name like '%" + ownerName + "%'"
+ " and p.owner_id=o.id and p.id>all(select top " + m
+ " p.id from pets p,owners o where p.name like '%" + petName
+ "%' and o.name like '%" + ownerName + "%'"
+ " and p.owner_id=o.id order by p.id)order by p.id";
ArrayList list = new ArrayList();
con = new DBUtils().getCon();
try {
pstmt = con.prepareStatement(sql);
rset = pstmt.executeQuery();
while (rset.next()) {
PetDTO pet = new PetDTO();
pet.setPetID(rset.getInt(1));
pet.setPetName(rset.getString(2));
pet.setPetOwnerID(rset.getInt(3));
pet.setPetOwnerName(rset.getString(4));
list.add(pet);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new DBException("database operation failed");
} finally {
new DBUtils().reaseSource(con, pstmt, rset);
}
if (list.isEmpty())
throw new PetOrOwnerNotExistsException(
"pet or owner is net existsException");
return list;
}
public PetDTO selectPetById(int petId) throws DBException {
String sql = "select p.id, p.name,p.birth_date,p.type_id,p.owner_id,o.name,t.name from pets p,owners o,types t"
+ " where p.id="
+ petId
+ " and p.owner_id=o.id and p.type_id=t.id";
con = new DBUtils().getCon();
PetDTO pet = null;
try {
pstmt = con.prepareStatement(sql);
rset = pstmt.executeQuery();
if (rset.next()) {
pet = new PetDTO();
pet.setPetID(rset.getInt(1));
pet.setPetName(rset.getString(2));
pet.setPetBirthDate(rset.getDate(3));
pet.setPetTypeID(rset.getInt(4));
pet.setPetOwnerID(rset.getInt(5));
pet.setPetOwnerName(rset.getString(6));
pet.setPetTypeName(rset.getString(7));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new DBException("database operation failed");
} finally {
new DBUtils().reaseSource(con, pstmt, rset);
}
System.out.println(sql);
return pet;
}
public void updatePet(PetDTO pet) throws DBException {
// Date petBirthDate=pet.getPetBirthDate();
String sql = "update pets set type_id=" + pet.getPetTypeID()
+ ",owner_id=" + pet.getPetOwnerID() + ",name='"
+ pet.getPetName() + "',birth_date='"
+ new java.sql.Date(pet.getPetBirthDate().getTime())
+ "' where id=" + pet.getPetID();
con = new DBUtils().getCon();
int i = 0;
try {
pstmt = con.prepareStatement(sql);
i = pstmt.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
new DBUtils().reaseSource(con, pstmt, rset);
}
if (i == 0)
throw new DBException("pet is not update");
System.out.println(sql);
}
public List selectPetTypes() throws DBException {
String sql = "select * from types";
con = new DBUtils().getCon();
ArrayList list = new ArrayList();
try {
pstmt = con.prepareStatement(sql);
rset = pstmt.executeQuery();
while (rset.next()) {
PetDTO pet = new PetDTO();
pet.setPetTypeID(rset.getInt("id"));
pet.setPetTypeName(rset.getString("name"));
list.add(pet);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new DBException("database operation failed");
} finally {
new DBUtils().reaseSource(con, pstmt, rset);
}
return list;
}
public List selectPetOwners() throws DBException {
String sql = "select * from owners";
con = new DBUtils().getCon();
ArrayList list = new ArrayList();
try {
pstmt = con.prepareStatement(sql);
rset = pstmt.executeQuery();
while (rset.next()) {
PetOwnerDTO owner = new PetOwnerDTO();
owner.setPetOwnerId(rset.getInt("id"));
owner.setPetOwnerName(rset.getString("name"));
owner.setPetOwnerAddress(rset.getString("address"));
owner.setPetOwnerCity(rset.getString("city"));
owner.setPetOwnerTelNo(rset.getString("telephone"));
list.add(owner);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new DBException("database operation failed");
} finally {
new DBUtils().reaseSource(con, pstmt, rset);
}
return list;
}
public void addPet(PetDTO pet) throws DBException {
String sql = "insert into pets(name,birth_date,type_id,owner_id) values(?,?,?,?)";
con = new DBUtils().getCon();
try {
pstmt = con.prepareStatement(sql);
pstmt.setString(1, pet.getPetName());
pstmt
.setDate(2, new java.
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
相关信息; 更新宠物的主人的相关信息; 向系统中增加一个新客户; 浏览宠物的相关信息; 更新宠物的相关信息; 向系统中增加一个新宠物; 浏览宠物的访问历史记录; 向宠物的访问历史记录添加一次访问; 此外,诊所的职员在使用系统提供的上述功能之前需要进行登录。当职员不需要使用系统的上述功能时,也可退出系统
资源推荐
资源详情
资源评论
收起资源包目录
java项目---爱心宠物诊所 (132个子文件)
PetServiceImpl.class 12KB
PetInfoForm.class 5KB
PetAction.class 4KB
PetOwnerAction.class 4KB
PetVisitAction.class 3KB
PetMgrImpl.class 3KB
FenyeDao.class 3KB
PetOwnerForm.class 3KB
PetOperAction.class 3KB
VetAction.class 3KB
EmployeeAction.class 2KB
PetOwnerDTO.class 2KB
PetDTO.class 2KB
PetVisitForm.class 2KB
Fenye.class 2KB
DBUtils.class 2KB
Test.class 1KB
PetVisitDTO.class 1KB
EmployeeForm.class 1KB
IPetService.class 1KB
IPetMgr.class 1KB
SpecDTO.class 1KB
VetDTO.class 1KB
ShowFenyeAction.class 854B
MyActionServlet.class 833B
PetOrOwnerNotExistsException.class 788B
VetNotExistsException.class 767B
LoginFailedException.class 764B
VisitHistoryNotExist.class 754B
DBException.class 737B
EmpDTO.class 726B
PetMgrFactory.class 583B
.classpath 1KB
calendar-win2k-1.css 6KB
table.css 801B
default.css 749B
struts.jar 531KB
standard.jar 384KB
antlr.jar 350KB
jtds-1.2.jar 279KB
commons-beanutils.jar 184KB
commons-digester.jar 164KB
commons-validator.jar 82KB
jakarta-oro.jar 64KB
commons-logging.jar 37KB
commons-fileupload.jar 22KB
jstl.jar 20KB
PetServiceImpl.java 13KB
Test.java 6KB
PetInfoForm.java 6KB
PetOwnerForm.java 4KB
PetOwnerAction.java 4KB
PetAction.java 4KB
PetVisitAction.java 3KB
PetMgrImpl.java 3KB
PetVisitForm.java 3KB
PetOperAction.java 3KB
FenyeDao.java 2KB
EmployeeAction.java 2KB
VetAction.java 2KB
PetOwnerDTO.java 2KB
PetDTO.java 2KB
EmployeeForm.java 2KB
Fenye.java 1KB
IPetMgr.java 1KB
IPetService.java 1KB
DBUtils.java 1KB
PetVisitDTO.java 982B
ShowFenyeAction.java 900B
SpecDTO.java 662B
VetDTO.java 661B
PetOrOwnerNotExistsException.java 575B
MyActionServlet.java 548B
VetNotExistsException.java 540B
VisitHistoryNotExist.java 529B
LoginFailedException.java 526B
DBException.java 481B
EmpDTO.java 380B
PetMgrFactory.java 231B
calendar.js 50KB
calendar-setup.js 5KB
calendar-en.js 3KB
ownerupdate.jsp 3KB
petsearch_name.jsp 3KB
petview_name.jsp 3KB
petupdate.jsp 3KB
petnew.jsp 3KB
petvisithistory.jsp 2KB
petnewvisit.jsp 2KB
newpetowner.jsp 2KB
petsearch.jsp 2KB
vetsearch_name.jsp 2KB
login.jsp 1KB
vetsearch.jsp 1KB
top.jsp 909B
error.jsp 853B
taglibs.jsp 370B
tail.jsp 304B
closeWindow.jsp 162B
.struts-config.mex 9KB
共 132 条
- 1
- 2
资源评论
- yy1820382015-04-29还行吧,借鉴一下,谢谢
- xhy6232013-11-27帮助还是有的,谢谢
- lc102883752013-02-18不错啊 要是注释详细点就更好 了
- 安末年2012-09-07还行,帮助还是有的!
sunachjoy
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功