首页>代码>java swing开发图书馆管理系统>/Librarians/src/data/BookDao.java
package data;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import entity.Book;

public class BookDao {
	//根据图书编号,获得单个图书实体
	public static Book selectBook(String id) {
		String sql = "select *  from book where id='" + id +"'";
		ResultSet rs = BaseDao.executeQuery(sql);
		Book book = null;
		try {
			if (rs.next()) {
				book = new Book();
				book.setId(rs.getString("id"));
				book.setType(rs.getString("type"));
				book.setName(rs.getString("name"));
				book.setAuthor(rs.getString("author"));
				book.setTranslator(rs.getString("translator"));
				book.setPublisher(rs.getString("publisher"));
				book.setPublish_time(rs.getDate("publish_time"));
				book.setPrice(rs.getDouble("price"));
				book.setStock(rs.getInt("stock"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		BaseDao.close();
		return book;
	}
	
	//获得满足sql语句的图书实体列表
	public static List selectBookList(String sql) {
		List list = new ArrayList();
		ResultSet rs = BaseDao.executeQuery(sql);
		try {
			while (rs.next()) {
				Book book = new Book();
				book.setId(rs.getString("id"));
				book.setType(rs.getString("type"));
				book.setName(rs.getString("name"));
				book.setAuthor(rs.getString("author"));
				book.setTranslator(rs.getString("translator"));
				book.setPublisher(rs.getString("publisher"));
				book.setPublish_time(rs.getDate("publish_time"));
				book.setPrice(rs.getDouble("price"));
				book.setStock(rs.getInt("stock"));
				list.add(book);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		BaseDao.close();
		return list;
	}
}
最近下载更多
微信网友_6445756515635200  LV3 2023年12月21日
KAIzx11  LV8 2023年6月24日
huangzy  LV12 2023年6月11日
122378  LV3 2022年12月14日
微信网友_6191697646571520  LV6 2022年10月31日
13112360  LV2 2022年9月20日
gnnhka  LV10 2022年6月16日
fantesy  LV17 2022年5月15日
喃喵xxxx  LV6 2022年5月11日
543666826  LV34 2022年3月12日
最近浏览更多
无异偶  LV3 2024年12月30日
ZALZXB20030525 2024年7月1日
暂无贡献等级
xzw135246789  LV1 2024年6月15日
微信网友_6808953284677632  LV2 2024年6月5日
123456cjj  LV1 2024年6月2日
sodkj123  LV16 2024年4月29日
akittyboy  LV9 2024年3月22日
asddwh  LV13 2023年12月26日
求学的熊猫  LV11 2023年12月25日
微信网友_6786215447367680  LV5 2023年12月21日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友