List of usage examples for org.apache.commons.dbutils.handlers BeanHandler BeanHandler
public BeanHandler(Class<T> type)
From source file:cn.itcast.bbs.dao.AddressDao.java
public Address findAddressByIp(String ip) throws SQLException { QueryRunner runner = new QueryRunner(JdbcUtil.getDataSource()); String sql = "select *from address;"; Address address = runner.query(sql, new BeanHandler(Address.class)); return address; }
From source file:cn.itcast.bbs.dao.AdminDao.java
public Admin findAdminByType(String title) throws SQLException { QueryRunner runner = new QueryRunner(JdbcUtil.getDataSource()); String sql = "select *from admin where title = ?"; Admin admin = runner.query(sql, new BeanHandler(Admin.class), title); return admin; }
From source file:cn.itcast.bbs.dao.UserDao.java
public User findUser(String username) throws SQLException { QueryRunner runner = new QueryRunner(JdbcUtil.getDataSource()); String sql = "select *from user where username = ?"; User userFromDB = runner.query(sql, new BeanHandler(User.class), new Object[] { username }); return userFromDB; }
From source file:cn.itcast.bbs.dao.FlowDao.java
public Flow showFlow(Date date) throws SQLException { QueryRunner runner = new QueryRunner(JdbcUtil.getDataSource()); String sql = "select *from flow where historydate = ?"; Flow flow = runner.query(sql, new BeanHandler(Flow.class), new java.sql.Date(date.getTime())); return flow;//from ww w . j a va 2 s . c o m }
From source file:com.ruihu.easyshop.user.dao.UserDao.java
public User findByLoginnameAndPassword(String loginname, String loginpass) throws SQLException { String sql = "select * from t_user where loginname=? and loginpass=?"; return qr.query(sql, new BeanHandler<User>(User.class), loginname, loginpass); }
From source file:com.geaviation.controller.LoginController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView mv = new ModelAndView(); DataSource ds = (DataSource) this.getApplicationContext().getBean("myDataSource"); try {//from ww w. j a v a 2s. c om String username = request.getParameter("username"); String password = request.getParameter("password"); //String status = "FAILURE"; QueryRunner run = new QueryRunner(ds); ResultSetHandler<UsersBean> user = new BeanHandler<UsersBean>(UsersBean.class); Object[] params = new Object[2]; params[0] = username; params[1] = password; UsersBean ub = run.query("select * from user_account where UNAME =? and UPASSWORD =?", user, params); if (ub != null) { mv.addObject("username", username); mv.setViewName("home"); } else { mv.addObject("error", "true"); mv.setViewName("index"); } } catch (Exception e) { e.printStackTrace(); } return mv; }
From source file:cn.itcast.bbs.dao.TypeDao.java
public Type findTypeById(int id) throws SQLException { QueryRunner runner = new QueryRunner(JdbcUtil.getDataSource()); String sql = "select *from type where id=?;"; Type type = runner.query(sql, new BeanHandler(Type.class), id); return type;// w w w. j a v a 2 s .c o m }
From source file:com.neu.controller.AdditionSuccessController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { //throw new UnsupportedOperationException("Not yet implemented"); int result = 0; DataSource ds = (DataSource) this.getApplicationContext().getBean("myDataSource"); ModelAndView mv = new ModelAndView(); HttpSession session = request.getSession(); int count = (Integer) (session.getAttribute("count")); try {/*w ww.j a va 2s.com*/ QueryRunner run = new QueryRunner(ds); ResultSetHandler<Books> books = new BeanHandler<Books>(Books.class); for (int i = 1; i <= count; i++) { String isbnField = "isbn" + i; String titleField = "title" + i; String authorField = "author" + i; String priceField = "price" + i; String isbn = request.getParameter(isbnField).replaceAll("<|>|@|;|,|=|}|$|&", ""); String title = request.getParameter(titleField).replaceAll("<|>|@|;|,|=|}|$|&", ""); String author = request.getParameter(authorField).replaceAll("<|>|@|;|,|=|}|$|&", ""); float price = Float .parseFloat(request.getParameter(priceField).replaceAll("<|>|@|;|,|=|}|$|&", "")); Object[] params = new Object[4]; params[0] = isbn; params[1] = title; params[2] = author; params[3] = price; result = run.update("Insert into books(isbn,title,authors,price) values(?,?,?,?)", params); } } catch (Exception ex) { System.out.println("Details Not Added In DB!! " + ex.getMessage()); } if (result > 0) { mv.setViewName("success"); } else { mv.setViewName("error"); } return mv; }
From source file:com.pinterest.deployservice.db.DBDataDAOImpl.java
@Override public DataBean getById(String id) throws Exception { ResultSetHandler<DataBean> h = new BeanHandler<DataBean>(DataBean.class); return new QueryRunner(dataSource).query(GET_DATA_BY_ID, h, id); }
From source file:com.pinterest.deployservice.db.DBAgentErrorDAOImpl.java
@Override public AgentErrorBean get(String hostName, String envId) throws Exception { ResultSetHandler<AgentErrorBean> h = new BeanHandler<AgentErrorBean>(AgentErrorBean.class); return new QueryRunner(dataSource).query(GET_ERROR, h, hostName, envId); }