List of usage examples for org.apache.commons.dbutils.handlers BeanListHandler BeanListHandler
public BeanListHandler(Class<T> type)
From source file:DbUtilsUseBeanMySQL.java
public static void main(String[] args) { Connection conn = null;//from w w w . j a v a2 s . co m String jdbcURL = "jdbc:mysql://localhost/octopus"; String jdbcDriver = "com.mysql.jdbc.Driver"; String user = "root"; String password = "root"; try { DbUtils.loadDriver(jdbcDriver); conn = DriverManager.getConnection(jdbcURL, user, password); QueryRunner qRunner = new QueryRunner(); List beans = (List) qRunner.query(conn, "select id, name from animals_table", new BeanListHandler(Employee.class)); for (int i = 0; i < beans.size(); i++) { Employee bean = (Employee) beans.get(i); bean.print(); } } catch (SQLException e) { // handle the exception e.printStackTrace(); } finally { DbUtils.closeQuietly(conn); } }
From source file:ir.zank.core.db.dbreader.java
public List<category> allcateg(String id) { try {//from www . j a v a2 s .co m List<category> categs = qr.query("select * from category where category_idcategory=?", new BeanListHandler<category>(category.class), id); System.out.println(categs.size()); return categs; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }
From source file:cn.itcast.bbs.dao.TypeDao.java
public List<Type> findAllType() throws SQLException { List<Type> typeList = null; QueryRunner runner = new QueryRunner(JdbcUtil.getDataSource()); String sql = "select *from type;"; typeList = runner.query(sql, new BeanListHandler(Type.class)); return typeList; }
From source file:cn.itcast.bbs.dao.ReplyDao.java
public List<Reply> showAllReplyByTopicId(int id) throws SQLException { List<Reply> replyList = null; QueryRunner runner = new QueryRunner(JdbcUtil.getDataSource()); String sql = "select *from reply where topic_id = ? order by time;"; replyList = runner.query(sql, new BeanListHandler(Reply.class), id); return replyList; }
From source file:cn.itcast.bbs.dao.TopicDao.java
public List<Topic> showAllTopicByTypeId(int id) throws SQLException { List<Topic> topicList = null; QueryRunner runner = new QueryRunner(JdbcUtil.getDataSource()); String sql = "select *from topic where type_id = ? order by time desc;"; topicList = runner.query(sql, new BeanListHandler(Topic.class), id); return topicList; }
From source file:ir.zank.core.db.dbreader.java
public List<city> allcity() { try {//w ww. java2s .co m List<city> citys = qr.query("select * from city ", new BeanListHandler<city>(city.class)); System.out.println(citys.size()); return citys; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }
From source file:com.mmone.gpdati.allotment.GpDatiDbDispoMap.java
private void loadAll() throws SQLException { String query = "SELECT * FROM PUBLIC.GPDATI_DISPO"; ResultSetHandler<List<GpDatiDispoRecord>> h = new BeanListHandler<GpDatiDispoRecord>( GpDatiDispoRecord.class); List<GpDatiDispoRecord> recs = database.getQueryRunner().query(query, h); for (GpDatiDispoRecord rec : recs) { this.put(rec.getKey(), rec); }/* w w w . j a v a 2 s . c om*/ }
From source file:com.mmone.gpdati.config.GpDatiDbRoomMap.java
private void loadAll() throws SQLException { String query = "SELECT * FROM PUBLIC.RELATION_GPDATI"; ResultSetHandler<List<GpDatiRoomRecord>> h = new BeanListHandler<GpDatiRoomRecord>(GpDatiRoomRecord.class); List<GpDatiRoomRecord> recs = database.getQueryRunner().query(query, h); for (GpDatiRoomRecord rec : recs) { //System.out.println( rec.toString()); if (rec != null && rec.getGpstru() != null && rec.getGpstru() != null) this.put(rec.getGpstru(), rec.getGproom(), rec); }//from www . j a v a 2 s . c om }
From source file:com.history.dao.StockDao.java
public List<Tick> getStock(String id, Date dat) throws SQLException { String sql = "select company_value as price,volume_change as volume from company_histories where listed_company_id=? and created_at between ? and ? order by created_at"; String currentDate = Util.getDate(dat); String endDate = Util.addDate(dat, 1); Object[] params = new Object[] { id, currentDate, endDate }; QueryRunner run = new QueryRunner(DataSourceFactory.getDataSource()); ResultSetHandler rsh = new BeanListHandler(Tick.class); return (List<Tick>) run.query(sql, rsh, params); }
From source file:com.rhino.data.db.TickerDao.java
public List<Ticker> getTickers(String equity, Date fromDate, Date toDate) throws SQLException { QueryRunner run = new QueryRunner(DataSourceFactory.getDataSource()); String sql = "select * from EOD where equity = ? and date between ? and ? order by date"; String from = Util.getDate(fromDate); String to = Util.getDate(toDate); Object[] params = new Object[] { equity, from, to }; ResultSetHandler rsh = new BeanListHandler(Ticker.class); return (List<Ticker>) run.query(sql, rsh, params); }