⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.java

📁 爱心”宠物诊所的职员需要使用系统提供的如下功能: 浏览诊所的兽医以及他们的专业特长; 浏览宠物的主人(即诊所的客户)的相关信息; 更新宠物的主人的相关信息; 向系统中增加一个新客户; 浏览宠
💻 JAVA
字号:
package com.wzxy.test;

import java.sql.Connection;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import com.wzxy.business.IPetMgr;
import com.wzxy.business.PetMgrFactory;
import com.wzxy.dao.IPetService;
import com.wzxy.dao.PetServiceImpl;
import com.wzxy.exception.DBException;
import com.wzxy.exception.LoginFailedException;
import com.wzxy.exception.PetOrOwnerNotExistsException;
import com.wzxy.exception.VisitHistoryNotExist;
import com.wzxy.pojos.EmpDTO;
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 Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
//		 TODO Auto-generated method stub
		/**
		 * 测试连接数据库
		 */
     /*  Connection con=new DBUtils().getCon();
       if(con!=null){
    	   System.out.println("success!");
       }else{
    	   System.out.println("worong!");
       }*/
	/**
	 * 测试LoginVerfy()
	 */
		
		/*IPetMgr factory=PetMgrFactory.getInstance();
		try {
			EmpDTO emp=factory.LoginVerify("aaa","123");
			if(emp!=null)
			{
				System.out.println("login success");
			}
		} catch (LoginFailedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		/**
		 * 测试浏览兽医方法VetSearch()
		 */
		/*IPetMgr factory=PetMgrFactory.getInstance();
		try {
			ArrayList list=(ArrayList) factory.VetSearch("j","拔牙");
			System.out.println(list.size());
			for(int i=0;i<list.size();i++)
			{
				VetDTO vet=(VetDTO) list.get(i);
				System.out.print(vet.getVetId());
				System.out.print(vet.getVetName());
				System.out.print(vet.getSpecId());
				System.out.print(vet.getSpecName());
				System.out.println();
			}
		} catch (DBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		/*SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
		dateFormat.setLenient(false);
		

		Calendar cal=new GregorianCalendar();
		Date date=null;
		try {
			date = dateFormat.parse("2006-2-5");
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		cal.setTime(date);
		cal.get(Calendar.YEAR);
		System.out.println("year:"+cal.get(Calendar.YEAR));
		System.out.println("month:"+cal.get(Calendar.MONTH));
		System.out.println("day:"+cal.get(Calendar.DAY_OF_MONTH));*/
		/**
		 * 测试浏览宠物方法PetSearch("c","")
		 */
		/*
		 IPetMgr factory=PetMgrFactory.getInstance();
		
		try {
			ArrayList list=(ArrayList) factory.PetSearch("c","");
			for(int i=0;i<list.size();i++)
			{
				PetDTO pet=(PetDTO)list.get(i);
				System.out.print(pet.getPetName());
				System.out.print("    "+pet.getPetOwnerName());
				System.out.print("    "+pet.getPetBirthDate());
				System.out.println();
			}
		} catch (PetOrOwnerNotExistsException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		*/
		/**
		 * 测试更新宠物信息方法selectPetById(3)和updatePet(pet)
		 */
	/*	IPetMgr service=PetMgrFactory.getInstance();
		try {
			PetDTO pet=service.selectPetById(3);
			System.out.println(pet.getPetName()+"  "+pet.getPetOwnerName());
		} catch (DBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		IPetMgr service=PetMgrFactory.getInstance();
		PetDTO pet=new PetDTO();
		pet.setPetTypeID(2);
		pet.setPetOwnerID(3);
		pet.setPetName("cat1");
		pet.setPetBirthDate("2004-1-2");
		pet.setPetID(2);
		try {
			int i=service.updatePet(pet);
			System.out.println("success");
		} catch (DBException e) {
			// TODO Auto-generated catch block
			System.out.println("failure");
			e.printStackTrace();
		}*/
		/**
		 * 测试增加宠物addPet(pet)
		 */
		/*SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
		IPetMgr service=PetMgrFactory.getInstance();
		String date="2004-1-2";
		PetDTO pet=new PetDTO();
		pet.setPetTypeID(2);
		pet.setPetOwnerID(3);
		pet.setPetName("cat3");
		try {
			pet.setPetBirthDate(dateFormat.parse(date));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			service.addPet(pet);
			System.out.println("success");
		} catch (DBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("failuer");
		}*/
		/**
		 * 测试增加和修改宠物主人方法addPetOwner(owner)、updatePetOwner(owner)
		 */
		/*String[] strHobby={"aaa","bbb"};
		IPetMgr service=PetMgrFactory.getInstance();
		PetOwnerDTO owner=new PetOwnerDTO();
		owner.setPetOwnerName("aaaaa");
		owner.setPetOwnerAddress("addrdss");
		owner.setPetOwnerCity("telephone");
		owner.setPetOwnerTelNo("12345");
		owner.setHobbies(strHobby);
		owner.setSex("nam");
		owner.setDemo("aaaaaa");
		owner.setRegDate(new Date());
		//owner.setPetOwnerId(6);
		try {
			service.addPetOwner(owner);
			//service.updatePetOwner(owner);
			System.out.println("success");
		} catch (DBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("failure");
		}*/
		/**
		 * 浏览宠物的访问历史记录searchPetVisitHistory(2)
		 */
		/*IPetMgr service=PetMgrFactory.getInstance();
		try {
			ArrayList list=(ArrayList) service.searchPetVisitHistory(2);
		    System.out.println(list.size()+"  ");
		} catch (DBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (VisitHistoryNotExist e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		/**
		 * 测试增加一次宠物的访问方法addVisitHistory(visit)
		 */
		SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
		String date="2005-1-1";
		IPetMgr service=PetMgrFactory.getInstance();
		PetVisitDTO visit=new PetVisitDTO();
		visit.setPetId(9);
		try {
			visit.setPetVisitDate(dateFormat.parse(date) );
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		visit.setPetVisitDescription("kkkkk");
		try {
			service.addVisitHistory(visit);
			System.out.println("success");
		} catch (DBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -