List of usage examples for org.apache.commons.dbutils QueryRunner QueryRunner
public QueryRunner(DataSource ds)
DataSource
to use. From source file:com.fluke.database.dataservice.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(DatabaseProperty.getDataSource()); ResultSetHandler rsh = new ArrayHandler(); Object[] query = (Object[]) run.query(sql, rsh); if (query == null || query.length == 0) { return null; }// w w w .j a va 2s .c o m return (Date) query[0]; }
From source file:com.geaviation.controller.MainController.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 2 s.c om*/ String action = request.getParameter("action"); String uri = request.getRequestURI(); if (uri.endsWith("home.htm")) { mv.setViewName("home"); } if ("request".equalsIgnoreCase(action)) { QueryRunner run = new QueryRunner(ds); ResultSetHandler<List<PartLicenseBean>> messages = new BeanListHandler<PartLicenseBean>( PartLicenseBean.class); List<PartLicenseBean> msg = run.query("select * from part_license", messages); if (msg != null) { System.out.println("printing license no received from DB: " + msg.get(0).getLicense_no()); mv.addObject("licenselist", msg); } mv.setViewName("request"); } else if ("validateinvoice".equalsIgnoreCase(action)) { mv.setViewName("validateinvoice"); } else if ("updatestatus".equalsIgnoreCase(action)) { mv.setViewName("updatestatus"); } else if ("viewshipstatus".equalsIgnoreCase(action)) { mv.setViewName("viewshipstatus"); } else if ("createrequest".equalsIgnoreCase(action)) { System.out.println("create request"); //go to database and insert } else if ("newfileSelect".equalsIgnoreCase(action)) { System.out.println("new file select"); String csvFile = request.getParameter("newfile"); if (csvFile != null) { StringBuffer data = readObj.getData(csvFile); System.out.println("printing data:" + data); mv.addObject("data", data); } mv.setViewName("validateinvoice"); //request.setAttribute("selected", "filedata"); } } catch (Exception e) { e.printStackTrace(); } return mv; }
From source file:com.pinterest.arcee.db.DBHealthCheckErrorDAOImpl.java
@Override public void insertHealthCheckError(HealthCheckErrorBean healthCheckErrorBean) throws Exception { SetClause setClause = healthCheckErrorBean.genSetClause(); String clause = String.format(INSERT_HEALTH_CHECK_ERROR, setClause.getClause()); new QueryRunner(dataSource).update(clause, setClause.getValueArray()); }
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); }
From source file:com.fluke.database.dataservice.EODDao.java
public Date getNextTradingDay(String date) throws SQLException { String sql = "select cast(min(date) as date) from intraday where date > '" + date + "'"; QueryRunner run = new QueryRunner(DatabaseProperty.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 a 2s .c om*/ return (java.sql.Date) query[0]; }
From source file:iudex.da.ContentReader.java
public List<UniMap> select(String query, Object... params) throws SQLException { QueryRunner runner = new QueryRunner(_dsource); return runner.query(query, new MapHandler(), params); }
From source file:com.example.data.UserData.java
public void removeUser(String username) throws SQLException { QueryRunner run = new QueryRunner(H2DB.getDataSource()); run.update("delete from user where user_name=?", username); }
From source file:com.neu.controller.LoginController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { DataSource ds = (DataSource) this.getApplicationContext().getBean("myDataSource"); String action = request.getParameter("action"); ModelAndView mv = new ModelAndView(); HttpSession session = request.getSession(); if (action.equalsIgnoreCase("login")) { try {/* ww w. j a v a 2 s . com*/ String userName = request.getParameter("user"); String password = request.getParameter("password"); 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 userstable where userName =? and userPassword=?", user, params); if (ub != null) { ResultSetHandler<List<MessageBean>> messages = new BeanListHandler<MessageBean>( MessageBean.class); List<MessageBean> msg = run.query("select * from messages where userName =?", messages, userName); session.setAttribute("userName", userName); session.setAttribute("messageList", msg); mv.setViewName("userhome"); } else { mv.addObject("error", "true"); mv.setViewName("index"); } } catch (Exception ex) { System.out.println("Error Message" + ex.getMessage()); } } else if (action.equalsIgnoreCase("logout")) { session.invalidate(); mv.setViewName("index"); } else if (action.equalsIgnoreCase("signup")) { System.out.println("sign up"); // // String userName = request.getParameter("user"); // String password = request.getParameter("password"); // String emailObj = request.getParameter("emailObj"); // // System.out.println("printing details: " + userName + " " +password + " "+emailObj); mv.setViewName("signup"); } else if (action.equalsIgnoreCase("signupsubmit")) { System.out.println("sign up submit"); String userName = request.getParameter("user"); String password = request.getParameter("password"); String email = request.getParameter("email"); System.out.println("printing details: " + userName + " " + password + " " + email); if (userName.equals("") || (password.equals("")) || (email.equals(""))) { System.out.println("empty values"); mv.addObject("error", "true"); } else { ResultSetHandler<UsersBean> user = new BeanHandler<UsersBean>(UsersBean.class); Object[] params = new Object[3]; params[0] = userName; params[1] = password; params[2] = email; QueryRunner run = new QueryRunner(ds); int inserts = run.update("insert into userstable (UserName,UserPassword,UserEmail) values (?,?,?)", params);//Logic to insert into table System.out.println("inserts value " + inserts); if (inserts > 0) { mv.addObject("success", "true"); Email emailObj = new SimpleEmail(); emailObj.setHostName("smtp.googlemail.com");//If a server is capable of sending emailObj, then you don't need the authentication. In this case, an emailObj server needs to be running on that machine. Since we are running this application on the localhost and we don't have a emailObj server, we are simply asking gmail to relay this emailObj. emailObj.setSmtpPort(465); emailObj.setAuthenticator( new DefaultAuthenticator("contactapplication2017@gmail.com", "springmvc")); emailObj.setSSLOnConnect(true); emailObj.setFrom("webtools@hello.com");//This emailObj will appear in the from field of the sending emailObj. It doesn't have to be a real emailObj address.This could be used for phishing/spoofing! emailObj.setSubject("TestMail"); emailObj.setMsg("This is spring MVC Contact Application sending you the email"); emailObj.addTo(email);//Will come from the sign up details emailObj.send(); } } mv.setViewName("signup"); } return mv; }
From source file:com.pinterest.deployservice.db.DBRatingsDAOImpl.java
@Override public void insert(RatingBean bean) throws Exception { SetClause setClause = bean.genSetClause(); String clause = String.format(INSERT_RATING_TEMPLATE, setClause.getClause()); new QueryRunner(dataSource).update(clause, setClause.getValueArray()); }