1 /**
2 * 2017-5-23上午11:58:03
3 *
4 */
5 public class BookDaoImpl extends BaseDao implements BookDao {
6 // 查询数据库中所有的新闻信息
7 public List<Books> findBooksList() {
8 String sql = "select * from book_info";
9 List<Books> books = new ArrayList<Books>();
10 rs = executeQuery(sql);
11 try {
12 while (rs.next()) {
13 Books book = new Books();
14 book.setBookId(rs.getInt("bookId"));
15 book.setBookCde(rs.getString("bookCde"));
16 book.setBookName(rs.getString("bookName"));
17 book.setBookType(rs.getInt("bookType"));
18 book.setBookAuthor(rs.getString("bookAuthor"));
19 book.setPublishPress(rs.getString("publishPress"));
20 book.setPublishDate(rs.getDate("publishDate"));
21 book.setBorrowed(rs.getInt("borrowed"));
22 book.setCreatedBy(rs.getString("createdBy"));
23 book.setCreationTime(rs.getDate("creationTime"));
24 book.setLastUpdateTime(rs.getDate("lastUpdateTime"));
25 books.add(book);
26 }
27 } catch (SQLException e) {
28 // TODO Auto-generated catch block
29 e.printStackTrace();
30 }
31 return books;
32 }
33
34 // 查询指定的新闻信息
35 public Books findBooksById(Books books) {
36 String sql = "select * from book_info where id=?";
37 Object[] params = { books.getBookId() };
38 rs = executeQuery(sql, params);
39 Books book = null;
40 try {
41 while (rs.next()) {
42 book = new Books();
43 book.setBookId(rs.getInt("bookId"));
44 book.setBookCde(rs.getString("bookCde"));
45 book.setBookName(rs.getString("bookName"));
46 book.setBookType(rs.getInt("bookType"));
47 book.setBookAuthor(rs.getString("bookAuthor"));
48 book.setPublishPress(rs.getString("publishPress"));
49 book.setPublishDate(rs.getDate("publishDate"));
50 book.setBorrowed(rs.getInt("borrowed"));
51 book.setCreatedBy(rs.getString("createdBy"));
52 book.setCreationTime(rs.getDate("creationTime"));
53 book.setLastUpdateTime(rs.getDate("lastUpdateTime"));
54 }
55 } catch (SQLException e) {
56 // TODO Auto-generated catch block
57 e.printStackTrace();
58 }
59 return book;
60 }
61
62 // 删除指定的新闻信息
63 public int deleteBooksById(Books books) {
64 String sql = "delete * from book_info where id=?";
65 Object[] params = { books.getBookId() };
66 int rows = executeUpdate(sql, params);
67
68 return rows;
69 }
70
71 // 修改指定的新闻信息
72 public int updateBooksById(Books books) {
73 String sql = "update book_info set bookCde=?,bookName=?,bookType=?,"
74 + "bookAuthor=?,publishPress=?,borrowed=?,createdBy=?,creationTime=?";
75 Object[] params = { books.getBookCde(), books.getBookName(),
76 books.getBookType(), books.getBookAuthor(),
77 books.getPublishPress(), books.getBorrowed(),
78 books.getCreatedBy(), books.getCreationTime() };
79 return executeUpdate(sql, params);
80 }
81
82 // 新增新闻信息
83 public int addBooks(Books books) {
84 String sql = "insert into book_info set bookCde=?,bookName=?,bookType=?,"
85 + "bookAuthor=?,publishPress=?,borrowed=?,createdBy=?,creationTime=?";
86 Object[] params = { books.getBookCde(), books.getBookName(),
87 books.getBookType(), books.getBookAuthor(),
88 books.getPublishPress(), books.getBorrowed(),
89 books.getCreatedBy(), books.getCreationTime() };
90 return executeUpdate(sql, params);
91 }
92
93 // 获取总记录数
94 public int getTotalCountSize() {
95 String sql = "select count(1) as count from book_info";
96 rs = executeQuery(sql);
97 int totalCount = 0;
98 try {
99 while (rs.next()) {
100 totalCount = rs.getInt("count");
101
102 }
103 } catch (SQLException e) {
104 // TODO Auto-generated catch block
105 e.printStackTrace();
106 }
107 return totalCount;
108 }
109
110 // 分页查询
111 public List<Books> getBooksByPageList(int pageIndex, int pageSize) {
112 String sql = "select * from book_info limit ?,?";
113 List<Books> list = new ArrayList<Books>();
114 pageIndex = (pageIndex - 1) * pageSize;
115 Object[] params = { pageIndex, pageSize };
116 rs = executeQuery(sql, params);
117 try {
118 while (rs.next()) {
119 Books book = new Books();
120 book.setBookId(rs.getInt("bookId"));
121 book.setBookCde(rs.getString("bookCde"));
122 book.setBookName(rs.getString("bookName"));
123 book.setBookType(rs.getInt("bookType"));
124 book.setBookAuthor(rs.getString("bookAuthor"));
125 book.setPublishPress(rs.getString("publishPress"));
126 book.setPublishDate(rs.getDate("publishDate"));
127 book.setBorrowed(rs.getInt("borrowed"));
128 book.setCreatedBy(rs.getString("createdBy"));
129 book.setCreationTime(rs.getDate("creationTime"));
130 book.setLastUpdateTime(rs.getDate("lastUpdateTime"));
131 list.add(book);
132 }
133 } catch (SQLException e) {
134 // TODO Auto-generated catch block
135 e.printStackTrace();
136 }
137 return list;
138 }
139
140 }