package dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import dto.History;
import dto.Pet;
import dto.PetType;
import factory.DBConnection;
public class PetDAO {
public static boolean addPet(Pet pet){
Connection conn = null;
PreparedStatement ps = null;
int rs = 0;
boolean flag=false;
try {
conn = DBConnection.getConn();
ps = conn.prepareStatement("insert into tb_pet(pet_name,pet_type,pet_birthday,pet_master) values(?,?,?,?)");
ps.setString(1,pet.getPet_name());
ps.setInt(2, pet.getPet_type_index());
ps.setString(3, pet.getPet_birthday());
ps.setString(4, pet.getPet_master());
rs = ps.executeUpdate();
if(rs==1) {
flag=true;
}
} catch (SQLException e) {
e.printStackTrace();
}
return flag;
}
public static boolean delPet(Pet pet){
Connection conn = null;
PreparedStatement ps = null;
int rs = 0;
boolean flag=false;
try {
conn = DBConnection.getConn();
ps = conn.prepareStatement("delete from tb_pet where pet_id=?");
ps.setInt(1, Integer.parseInt(pet.getPet_id()));
rs = ps.executeUpdate();
if(rs==1) {
flag=true;
}
} catch (SQLException e) {
e.printStackTrace();
}
return flag;
}
public static boolean updatePet(Pet pet){
Connection conn = null;
PreparedStatement ps = null;
int rs = 0;
boolean flag=false;
try {
conn = DBConnection.getConn();
ps = conn.prepareStatement("update tb_pet set pet_name=?,pet_type=?,pet_birthday=?,pet_master=? where pet_id=?");
ps.setString(1, pet.getPet_name());
ps.setInt(2, pet.getPet_type_index());
ps.setString(3, pet.getPet_birthday());
ps.setString(4, pet.getPet_master());
ps.setInt(5, Integer.parseInt(pet.getPet_id()));
rs = ps.executeUpdate();
if(rs==1) {
flag=true;
}
} catch (SQLException e) {
e.printStackTrace();
}
return flag;
}
public static List<Pet> querryAll(){
List<Pet> petlist=new ArrayList<Pet>();
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
Pet pet=null;
try {
conn = DBConnection.getConn();
ps = conn.prepareStatement("select a.*,b.type_name from tb_pet a,tb_pet_type b where a.pet_type=b.type_id");
rs = ps.executeQuery();
while(rs.next()) {
pet =new Pet();
pet.setPet_id(rs.getString("pet_id"));
pet.setPet_name(rs.getString("pet_name"));
pet.setPet_type(rs.getString("type_name"));
pet.setPet_birthday(rs.getString("pet_birthday"));
pet.setPet_master(rs.getString("pet_master"));
petlist.add(pet);
}
} catch (SQLException e) {
e.printStackTrace();
}
return petlist;
}
public static List<Pet> querryByName(Pet pet){
List<Pet> petlist=new ArrayList<Pet>();
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
Pet returnpet=null;
try {
conn = DBConnection.getConn();
ps = conn.prepareStatement("select a.*,b.type_name from tb_pet a,tb_pet_type b where a.pet_type=b.type_id and pet_name=?");
ps.setString(1, pet.getPet_name());
rs = ps.executeQuery();
while(rs.next()) {
returnpet =new Pet();
returnpet.setPet_id(rs.getString("pet_id"));
returnpet.setPet_name(rs.getString("pet_name"));
returnpet.setPet_type(rs.getString("type_name"));
returnpet.setPet_birthday(rs.getString("pet_birthday"));
returnpet.setPet_master(rs.getString("pet_master"));
petlist.add(returnpet);
}
} catch (SQLException e) {
e.printStackTrace();
}
return petlist;
}
//通过主人名检索
public static List<Pet> querryByMaterName(Pet pet){
List<Pet> petlist=new ArrayList<Pet>();
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
Pet returnpet=null;
try {
conn = DBConnection.getConn();
ps = conn.prepareStatement("select a.*,b.type_name from tb_pet a,tb_pet_type b where a.pet_type=b.type_id and pet_master=?");
ps.setString(1, pet.getPet_master());
rs = ps.executeQuery();
while(rs.next()) {
returnpet =new Pet();
returnpet.setPet_id(rs.getString("pet_id"));
returnpet.setPet_name(rs.getString("pet_name"));
returnpet.setPet_type(rs.getString("type_name"));
returnpet.setPet_birthday(rs.getString("pet_birthday"));
returnpet.setPet_master(rs.getString("pet_master"));
petlist.add(returnpet);
}
} catch (SQLException e) {
e.printStackTrace();
}
return petlist;
}
public static Pet querryById(Integer id){
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
Pet returnpet=null;
try {
conn = DBConnection.getConn();
ps = conn.prepareStatement("select a.*,b.type_name from tb_pet a,tb_pet_type b where a.pet_type=b.type_id and pet_id=?");
ps.setInt(1, id);
rs = ps.executeQuery();
if(rs.next()) {
returnpet =new Pet();
returnpet.setPet_id(rs.getString("pet_id"));
returnpet.setPet_name(rs.getString("pet_name"));
returnpet.setPet_type(rs.getString("type_name"));
returnpet.setPet_birthday(rs.getString("pet_birthday"));
returnpet.setPet_master(rs.getString("pet_master"));
returnpet.setPet_type_index(rs.getInt("pet_type"));
}
} catch (SQLException e) {
e.printStackTrace();
}
return returnpet;
}
public static List<PetType> getType(){
List<PetType> typelist=new ArrayList<PetType>();
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
PetType petType=null;
try {
conn = DBConnection.getConn();
ps = conn.prepareStatement("select * from tb_pet_type ");
rs = ps.executeQuery();
while(rs.next()) {
petType=new PetType();
petType.setType_id(rs.getInt("type_id"));
petType.setType_name(rs.getString("type_name"));
typelist.add(petType);
}
} catch (SQLException e) {
e.printStackTrace();
}
return typelist;
}
//添加病历
public static boolean addPetRecord(History his){
Connection conn = null;
PreparedStatement ps = null;
int rs = 0;
boolean flag=false;
try {
conn = DBConnection.getConn();
ps = conn.prepareStatement("insert into tb_clinic_history(pet_id,record_details,record_doctor) values(?,?,?)");
ps.setInt(1, his.getPet_id());
ps.setString(2, his.getRecord_details());
ps.setString(3, his.getRecord_doctor());
rs = ps.executeUpdate();
if(rs==1) {
flag=true;
}
} catch (SQLException e) {
e.printStackTrace();
}
return flag;
}
//查询病历
public static List<History> getHistory(Pet pet){
List<History> hislist=new ArrayList<History>();
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
History his=null;
try {
conn = DBConnection.getConn();
ps = conn.prepareStatement("select * from tb_clinic_history where pet_id=?");
ps.setInt(1, Integer.parseInt(pet.getPet_id()));
rs = ps.executeQuery();
while(rs.next()) {
his=new History();
his.setRecord_id(rs.getInt("record_id"));
his.setRecord_time(rs.getString("record_time"));
his.setRecord_details(rs.getString("record_details"));
his.setRecord_doctor(rs.getString("record_doctor"));
hislist.add(his);
}
} catch (SQLException e) {
e.printStackTrace();
}
return hislist;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
宠物诊所.zip (86个子文件)
宠物诊所
数据库
db_pet.sql 5KB
实际数据库设计.doc 43KB
pet
src
dto
PetType.java 330B
Vet.java 674B
Customer.java 952B
Admin.java 509B
Pet.java 992B
History.java 869B
factory
DBConnection.java 616B
dao
AdminDAO.java 2KB
VetDAO.java 2KB
PetDAO.java 7KB
CustomerDAO.java 5KB
struts.xml 3KB
util
Image.java 2KB
action
CustomerAction.java 2KB
LoginAction.java 875B
VetAction.java 1KB
PetAction.java 2KB
test
Test.java 319B
.classpath 557B
.mystrutsdata 240B
.mymetadata 282B
.myeclipse
.project 1KB
WebRoot
validate.jsp 316B
META-INF
MANIFEST.MF 36B
showpet.jsp 3KB
addrecord.jsp 2KB
addcustomer.jsp 1KB
mainfra.html 1KB
showhistory.jsp 1KB
js
lang
zh-cn.js 1KB
en.js 644B
zh-tw.js 1KB
calendar.js 21KB
skin
WdatePicker.css 158B
default
img.gif 2KB
datepicker.css 4KB
datePicker.gif 1KB
whyGreen
img.gif 2KB
datepicker.css 4KB
bg.jpg 307B
WdatePicker.js 9KB
showtime.js 1KB
index.jsp 4KB
updatecustomer.jsp 2KB
css
mainfrm.css 290B
addmainfrm.css 315B
left.jsp 2KB
manage.html 652B
addpet.jsp 2KB
showcustomer.jsp 2KB
updatepet.jsp 2KB
img
error.png 907B
right.png 2KB
welcome.gif 10KB
left.jpg 9KB
bg.JPG 9KB
1.jpg 59KB
m.gif 53B
valitormsg.png 1KB
manage
addadmin.jsp 1KB
image.jsp 377B
showvet.jsp 2KB
WEB-INF
classes
dto
Vet.class 1KB
Customer.class 1KB
Pet.class 2KB
History.class 1KB
PetType.class 747B
Admin.class 926B
factory
DBConnection.class 1KB
dao
PetDAO.class 7KB
CustomerDAO.class 4KB
AdminDAO.class 3KB
VetDAO.class 3KB
struts.xml 3KB
util
Image.class 2KB
action
VetAction.class 2KB
CustomerAction.class 3KB
LoginAction.class 2KB
PetAction.class 3KB
test
Test.class 1KB
lib
mysql-connector-java-5.1.13-bin.jar 750KB
web.xml 671B
参考宠物诊所系统数据库设计.doc 98KB
宠物诊所系统需求和需求分析说明书.doc 107KB
共 86 条
- 1
资源评论
- surfingyou2013-07-11初学者,要是有注释就能看得明白些了
- single_girl2012-12-22非常好 struts problem怎么解决啊
- 潜力股2012-12-18非常好,开发完就更好了
- lc102883752013-02-18非常好 ,要是能在详细点就更好了
风之阡陌
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功