List of usage examples for org.apache.commons.dbutils QueryRunner QueryRunner
public QueryRunner(DataSource ds)
DataSource
to use. 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 {//from w w w. java 2 s . c o m 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.rhino.data.db.EquityDao.java
public void changeGroup(String equity, String group) throws SQLException { String sql = "update ticker set grade ='" + group + "' where equity='" + equity + "'"; QueryRunner run = new QueryRunner(DataSourceFactory.getDataSource()); run.update(sql);/*from w w w . j ava 2s .c o m*/ }
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); }
From source file:com.fluke.database.dataservice.EquityDao.java
public void changeGroup(String equity, String group) throws SQLException { String sql = "update ticker set grade ='" + group + "' where equity='" + equity + "'"; QueryRunner run = new QueryRunner(DatabaseProperty.getDataSource()); run.update(sql);/*from w w w . j a v a 2s . 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:cn.itcast.bbs.dao.ReplyDao.java
public void addReply(Reply reply, int topicId) throws Exception { QueryRunner runner = new QueryRunner(JdbcUtil.getDataSource()); String sql = "insert into reply(title,name,content,topic_id) values(?,?,?,?);"; runner.update(sql, new Object[] { reply.getTitle(), reply.getName(), reply.getContent(), topicId }); }
From source file:cn.itcast.bbs.dao.TopicDao.java
public void addTopic(Topic topic, int id) throws SQLException { QueryRunner runner = new QueryRunner(JdbcUtil.getDataSource()); String sql = "insert into topic(title,name,content,type_id) values(?,?,?,?);"; runner.update(sql, new Object[] { topic.getTitle(), topic.getName(), topic.getContent(), id }); }
From source file:genepi.db.JdbcDataAccessObject.java
public JdbcDataAccessObject(Database database) { this.database = database; runner = new QueryRunner(database.getDataSource()); }
From source file:com.rhino.data.db.EquityDao.java
public Date getLastTickerDetails(String equity) throws SQLException { String sql = " select cast(max(date) as date) from EOD where equity='" + equity + "'"; QueryRunner run = new QueryRunner(DataSourceFactory.getDataSource()); ResultSetHandler rsh = new ArrayHandler(); Object[] query = (Object[]) run.query(sql, rsh); if (query == null || query.length == 0) { return null; }/*from w ww. j a v a2 s .c o m*/ return (Date) query[0]; }
From source file:com.example.data.StoreData.java
public void deleteOrder(long orderId) throws SQLException { QueryRunner run = new QueryRunner(H2DB.getDataSource()); run.update("delete from order where id=?", orderId); }