CustomerDAO及CustomerDAOImpl的实现
package top.qaqaq.P43.dao;

import java.sql.Connection;
import java.sql.Date;
import java.util.List;

import top.qaqaq.P43.bean.Customer;

/*
 * 此接口用于规范针对于customers表的常用操作
 */
public interface CustomerDAO {

	/**
	 * 
	 * @Description 将cust对象添加到数据库中
	 * @author RichieZhang
	 * @date 2022年11月28日下午2:20:36
	 * @param conn
	 * @param cust
	 */
	void insert(Connection conn, Customer cust);

	/**
	 * 
	 * @Description 针对指定的id,删除表中的一条记录
	 * @author RichieZhang
	 * @date 2022年11月28日下午2:21:29
	 * @param conn
	 * @param id
	 */
	void deleteById(Connection conn, int id);

	/**
	 * 
	 * @Description 针对内存中的cust对象,去修改数据表中指定的记录
	 * @author RichieZhang
	 * @date 2022年11月28日下午2:23:35
	 * @param conn
	 * @param cust
	 */
	void update(Connection conn, Customer cust);

	/**
	 * 
	 * @Description 针对指定的id查询得到对应的Customer对象
	 * @author RichieZhang
	 * @date 2022年11月28日下午2:24:38
	 * @param conn
	 * @param id
	 */
	Customer getCustomerById(Connection conn, int id);

	/**
	 * 
	 * @Description 查询表中的所有记录构成的集合
	 * @author RichieZhang
	 * @date 2022年11月28日下午2:25:41
	 * @param conn
	 * @return
	 */
	List<Customer> getAll(Connection conn);

	/**
	 * 
	 * @Description 返回数据表中的数据的条目数
	 * @author RichieZhang
	 * @date 2022年11月28日下午2:26:57
	 * @param conn
	 * @return
	 */
	Long getCount(Connection conn);

	/**
	 * 
	 * @Description 返回数据表中最大的生日
	 * @author RichieZhang
	 * @date 2022年11月28日下午2:28:35
	 * @param conn
	 * @return
	 */
	Date getMaxBirth(Connection conn);
}
package top.qaqaq.P43.dao;

import java.sql.Connection;
import java.sql.Date;
import java.util.List;

import top.qaqaq.P42.dao.BaseDAO;
import top.qaqaq.P43.bean.Customer;

public class CustomerDAOImpl extends BaseDAO implements CustomerDAO {

	@Override
	public void insert(Connection conn, Customer cust) {
		
		String sql = "insert into customers(name,email,birth) values(?,?,?) ";
		
		update(conn, sql, cust.getName(),cust.getEmail(),cust.getBirth());
	}

	@Override
	public void deleteById(Connection conn, int id) {

		String sql = "delete from customers where id = ?";

		update(conn, sql, id);
	}

	@Override
	public void update(Connection conn, Customer cust) {

		String sql = "update customers set name = ?,email = ?, birth = ? where id = ?";

		update(conn, sql, cust.getName(), cust.getEmail(), cust.getBirth(), cust.getId());
	}

	@Override
	public Customer getCustomerById(Connection conn, int id) {

		String sql = "select id,name,email,birth from customers where id = ?";

		Customer customer = getInstance(conn, Customer.class, sql, id);

		return customer;
	}

	@Override
	public List<Customer> getAll(Connection conn) {

		String sql = "select id,name,email,birth from customers ";

		List<Customer> list = getForList(conn, Customer.class, sql);

		return list;
	}

	@Override
	public Long getCount(Connection conn) {

		String sql = "select count(*) from customers";

		return getValue(conn, sql);
	}

	@Override
	public Date getMaxBirth(Connection conn) {
		
		String sql = "select max(birth) from customers";
		
		return getValue(conn, sql);
		
	}

}
package top.qaqaq.P43.bean;

import java.sql.Date;

/*
 * ORM编程思想(object relational mapping)
 * 一个数据表对应一个java类
 * 表中的一条记录对应java类的一个对象
 * 表中的一个字段对应java类的一个属性
 * 
 */
public class Customer {

	private int id;
	private String name;
	private String email;
	private Date birth;

	public Customer() {
	}

	public Customer(int id, String name, String email, Date birth) {
		this.id = id;
		this.name = name;
		this.email = email;
		this.birth = birth;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public Date getBirth() {
		return birth;
	}

	public void setBirth(Date birth) {
		this.birth = birth;
	}

	@Override
	public String toString() {
		return "Customer [id=" + id + ", name=" + name + ", email=" + email + ", birth=" + birth + "]";
	}

}
package top.qaqaq.P43.bean;

import java.sql.Date;

public class Order {

	private int orderId;
	private String orderName;
	private Date orderDate;

	public Order() {
	}

	public Order(int orderId, String orderName, Date orderDate) {
		this.orderId = orderId;
		this.orderName = orderName;
		this.orderDate = orderDate;
	}

	public int getOrderId() {
		return orderId;
	}

	public void setOrderId(int orderId) {
		this.orderId = orderId;
	}

	public String getOrderName() {
		return orderName;
	}

	public void setOrderName(String orderName) {
		this.orderName = orderName;
	}

	public Date getOrderDate() {
		return orderDate;
	}

	public void setOrderDate(Date orderDate) {
		this.orderDate = orderDate;
	}

	@Override
	public String toString() {
		return "Order [orderId=" + orderId + ", orderName=" + orderName + ", orderDate=" + orderDate + "]";
	}

}
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇