java oop 第十二章宠物商店

DAO层
package cn.happy.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class BaseDao {
	Connection con = null;
	PreparedStatement ps = null;
    public ResultSet rs=null;
	private static final String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
	private static final String url = "jdbc:sqlserver://localhost:1433;DatabaseName=PetShop";
	private static final String username = "sa";
	private static final String pwd = "1";
	
	
	public Connection getCon()throws Exception{
		Class.forName(driver);
		if(con==null||con.isClosed()){
        con = DriverManager.getConnection(url, username, pwd);
		}
	return con;
	}
	
	
	
	
	//执行查询
	public ResultSet executeQuery(String sql,Object... obje) throws Exception{
		
		con=getCon();
		ps=con.prepareStatement(sql);
		for(int i=0;i<obje.length;i++){
			ps.setObject(i+1, obje[i]);
			
		}
		rs=ps.executeQuery();
		return rs;
	}
	//测试修改

	//执行修改
	
	public int execteUpdate(String sql,Object...object) throws Exception{
		
		con=getCon();
		ps=con.prepareStatement(sql);
		for(int i=0;i<object.length;i++){
			ps.setObject(i+1, object[i]);
			
		}
		int count=ps.executeUpdate();
		return count;
	}
	//单测增加
	
	//执行增加
public int execteadd(String sql,Object...object) throws Exception{
		
		con=getCon();
		ps=con.prepareStatement(sql);
		ps.executeUpdate();
		for(int i=0;i<object.length;i++){
			ps.setObject(i+1, object[i]);
			
		}
		int count=ps.executeUpdate();
		return count;
	}
	
//执行删除

//执行删除
public int exectedelete(String sql,Object...object) throws Exception{
	
	con=getCon();
	ps=con.prepareStatement(sql);
	ps.executeUpdate();
	for(int i=0;i<object.length;i++){
		ps.setObject(i+1, object[i]);
		
	}
	int count=ps.executeUpdate();
	return count;
}

	public void closeAll() throws Exception{
		
		if(rs!=null){
			
			rs.close();
		}
		if(ps!=null){
			
			ps.close();
		}
		if(con!=null){
			con.close();
		}
	}
	//
	
	
}

package cn.happy.dao;

import java.util.List;

import cn.happy.entity.Pet;
import cn.happy.entity.PetOwner;

public interface Petdao {
	public List<Pet> select1() throws Exception;
	public List<Pet> se1() throws Exception;
	public boolean up(int id) throws Exception;
	public List<Pet> poselect(int id) throws Exception;
	public List<Pet>  selectquan() throws Exception;
	Pet getPetById(int id) throws Exception;
	int buyPet(int petid,int ownerid) throws Exception;
    int sellPet(int storeid,int petid) throws Exception;
    public List<Pet> getOwnerPet(int ownerid) throws Exception ;
}
package cn.happy.dao;

import java.util.List;

import cn.happy.entity.Pet;
import cn.happy.entity.PetOwner;

public interface PetOwnerdao {
	//显示宠物主人名称
	public List<PetOwner> select2() throws Exception;
	public PetOwner DL(String name1) throws Exception;
	public boolean update1(int money,int id) throws Exception;
	public List<PetOwner> getnamebyid()throws Exception;
	public int getIdByName(String name) throws Exception ;
	public int updateByName(int money,String name) throws Exception ;
	public int updateMoneyByName(int money, String name) throws Exception ;
}

package cn.happy.dao;

import java.util.List;

import cn.happy.entity.PetStore;

public interface PetStoredao {
 public List<PetStore> select3() throws Exception;
 public PetStore DL(String name1) throws Exception; 
 

}

package cn.happy.dao;

public interface Accountdao {
public boolean add(int id)throws Exception;
int addAccount(int dealtype,int petid,int ownerid) throws Exception;
int addSellAccount(int dealtype,int petid,int ownerid,int storeid) throws Exception;
}

DAO Impl
package cn.happy.Impl;

import cn.happy.dao.Accountdao;
import cn.happy.dao.BaseDao;

public  class AccountdaoImpl extends BaseDao implements Accountdao {

	@Override
	//添加一条台账信息
	//宠物主人登录购买的宠物
	public boolean add(int id) throws Exception {
		boolean flag=false;
		String sql="insert into Account values(?,?,?)";
		int count=this.execteU
  • 6
    点赞
  • 47
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值