01 | package cn.itcast.dao.impl; |
02 |
03 | import java.sql.SQLException; |
04 | import java.util.List; |
05 |
06 | import org.apache.commons.dbutils.QueryRunner; |
07 | import org.apache.commons.dbutils.handlers.BeanHandler; |
08 | import org.apache.commons.dbutils.handlers.BeanListHandler; |
09 |
10 | import cn.itcast.dao.CategoryDao; |
11 | import cn.itcast.domain.Category; |
12 | import cn.itcast.exception.DaoException; |
13 | import cn.itcast.util.DBCPUtil; |
14 | /* |
15 | create table category( |
16 | id varchar(100) primary key, |
17 | name varchar(100) not null unique, |
18 | description varchar(255) |
19 | ); |
20 | */ |
21 | public class CategoryDaoImpl implements CategoryDao { |
22 | private QueryRunner qr = new QueryRunner(DBCPUtil.getDataSource()); |
23 | public void addCategory(Category c) { |
24 | try { |
25 | qr.update( "insert into category (id,name,description) values(?,?,?)" , c.getId(),c.getName(),c.getDescription()); |
26 | } catch (SQLException e) { |
27 | throw new DaoException(e); |
28 | } |
29 | } |
30 |
31 | public List<Category> findAll() { |
32 | try { |
33 | return qr.query( "select * from category" , new BeanListHandler<Category>(Category. class )); |
34 | } catch (SQLException e) { |
35 | throw new DaoException(e); |
36 | } |
37 | } |
38 |
39 | public Category findCatetoryById(String categoryId) { |
40 | try { |
41 | return qr.query( "select * from category where id=?" , new BeanHandler<Category>(Category. class ),categoryId); |
42 | } catch (SQLException e) { |
43 | throw new DaoException(e); |
44 | } |
45 | } |
46 |
47 | } |

蝙蝠大王 LV1
2024年6月23日
yy334455666 LV1
2024年6月19日
13190108824 LV1
2024年5月19日
罗清晨 LV13
2024年5月6日
asddwh LV13
2023年12月29日
1222222222222222222 LV2
2023年12月17日
3159792465 LV10
2023年9月1日
自知则知之1 LV2
2023年5月26日
微信网友_6468115061182464 LV1
2023年5月9日
Gjc175636312 LV2
2023年4月20日

徐长风 LV1
4小时前
微信网友_7461641148715008
4月10日
暂无贡献等级
66202943
1月4日
暂无贡献等级
mm1242 LV1
2024年12月19日
klllllllllllllllllll
2024年12月10日
暂无贡献等级
martiz
2024年7月13日
暂无贡献等级
樱花味小然子 LV5
2024年7月2日
soisoi
2024年6月28日
暂无贡献等级
蝙蝠大王 LV1
2024年6月23日
微信网友_6808953284677632 LV2
2024年6月21日