List of usage examples for java.sql ResultSet getDate
java.sql.Date getDate(String columnLabel) throws SQLException;
ResultSet
object as a java.sql.Date
object in the Java programming language. From source file:io.github.vteial.maxmoney.jdbc.CustomerRowMapper.java
@Override public Customer mapRow(ResultSet resultSet, int intRow) throws SQLException { Customer model = new Customer(); model.setCustomerCode(resultSet.getString("customer_code")); model.setCustomerName(resultSet.getString("customer_name")); model.setAddress(resultSet.getString("address")); model.setTown(resultSet.getString("town")); model.setCountry(resultSet.getString("country")); model.setPostalCode(resultSet.getString("postal_code")); model.setPhone1(resultSet.getString("phone1")); model.setPhone2(resultSet.getString("phone2")); model.setFax(resultSet.getString("fax")); model.setHandPhone(resultSet.getString("hand_phone")); model.setEmail(resultSet.getString("email")); model.setCustomerType(resultSet.getString("customer_type")); model.setAccountNo(resultSet.getString("account_no")); model.setBnLicenseNo(resultSet.getString("bn_license_no")); model.setLicenseExpiryDate(resultSet.getDate("license_expiry_date")); model.setBranchType(resultSet.getString("branch_type")); model.setStatus(resultSet.getString("status")); model.setPriority(resultSet.getInt("priority")); model.setCustomerLocation(resultSet.getString("customer_location")); model.setBaseCurrency(resultSet.getString("base_currency")); model.setLastBalance(resultSet.getFloat("last_balance")); model.setCreateUser(resultSet.getString("create_user")); model.setCreateDate(resultSet.getDate("create_date")); model.setCreateTime(resultSet.getDate("create_time")); model.setUpdateUser(resultSet.getString("update_user")); model.setUpdateDate(resultSet.getDate("update_date")); model.setUpdateTime(resultSet.getDate("update_time")); return model; }
From source file:nl.tudelft.stocktrader.derby.DerbyCustomerDAO.java
public List<Holding> getHoldings(String userID) throws DAOException { PreparedStatement selectHoldings = null; try {/*from w w w . j a v a 2 s . com*/ selectHoldings = sqlConnection.prepareStatement(SQL_SELECT_HOLDINGS); selectHoldings.setString(1, userID); ResultSet rs = selectHoldings.executeQuery(); List<Holding> holdings = new ArrayList<Holding>(); try { while (rs.next()) { Holding holding = new Holding(rs.getInt(1), rs.getDouble(2), rs.getBigDecimal(3), StockTraderUtility.convertToCalendar(rs.getDate(4)), rs.getString(5), rs.getInt(6)); holdings.add(holding); } } finally { try { rs.close(); } catch (SQLException e) { logger.debug("", e); } } return holdings; } catch (SQLException e) { throw new DAOException("", e); } finally { if (selectHoldings != null) { try { selectHoldings.close(); } catch (SQLException e) { logger.debug("", e); } } } }
From source file:com.microsoftopentechnologies.azchat.web.dao.UserDAOImpl.java
/** * This method populates userEntity from the result set object. * /*from www .ja va 2 s .c o m*/ * @param resultSet * @return * @throws SQLException */ public UserEntity generateUserObject(ResultSet resultSet) throws SQLException { UserEntity user = new UserEntity(); user.setUserID(resultSet.getInt(1)); user.setNameId(resultSet.getString(2)); user.setIdentityProvider(resultSet.getString(3)); user.setFirstName(resultSet.getString(4)); user.setLastName(resultSet.getString(5)); user.setPhotoBlobUrl(resultSet.getString(6)); user.setEmailAddress(resultSet.getString(7)); user.setPhoneCountryCode(resultSet.getInt(8)); user.setPhoneNumber(resultSet.getLong(9)); user.setDateCreated(resultSet.getDate(10)); user.setCreatedBy(resultSet.getDate(11)); user.setDateModified(resultSet.getDate(12)); user.setModifiedBy(resultSet.getDate(13)); return user; }
From source file:com.imagelake.android.purchasemanagement.Servlet_purchaseViseImages.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); try {// ww w .ja v a 2s. com String type = request.getParameter("type"); if (type != null && !type.equals("")) { if (type.equals("all")) { ja = new JSONArray(); li = new CartDAOImp().listdownloadedImages(); Images im; int i = 1; Categories c = null; Cart ct = null; User buyer = null; User Seller = null; if (!li.isEmpty()) { for (CartHasImages cartHasImages : li) { JSONObject jo = new JSONObject(); jo.put("cid", cartHasImages.getImg_id()); im = idi.getImageDetail(cartHasImages.getImg_id()); jo.put("title", im.getTitle()); jo.put("credit", cartHasImages.getCredits()); c = cadi.getCategory(im.getCategories_category_id()); jo.put("category", c.getCategory()); jo.put("date", cartHasImages.getDate()); ct = cdi.getACart(cartHasImages.getCart_id()); buyer = udi.getUser(ct.getUser_id()); Seller = udi.getUser(im.getUser_user_id()); jo.put("buyer", buyer.getUser_name()); jo.put("seller", Seller.getUser_name()); ja.add(jo); } System.out.println(ja.toJSONString()); out.write("json=" + ja.toJSONString()); } else { out.write("msg=No item found."); } } else if (type.equals("all_sort")) { ja = new JSONArray(); List<Categories> cli = cadi.listAllCategories(); JSONArray catAr = new JSONArray(); for (Categories categories : cli) { JSONObject jo = new JSONObject(); jo.put("id", categories.getCategory_id()); jo.put("category", categories.getCategory()); catAr.add(jo); } ja.add(catAr); List<User> usli = udi.listSellersBuyers(); JSONArray usAr = new JSONArray(); for (User user : usli) { JSONObject jo = new JSONObject(); jo.put("bid", user.getUser_id()); jo.put("bun", user.getUser_name()); usAr.add(jo); } ja.add(usAr); List<User> sli = udi.listAllSellers(); JSONArray seAr = new JSONArray(); for (User u : sli) { JSONObject jo = new JSONObject(); jo.put("sid", u.getUser_id()); jo.put("sun", u.getUser_name()); seAr.add(jo); } ja.add(seAr); System.out.println(ja.toJSONString()); out.write("json=" + ja.toJSONString()); } else if (type.equals("sort")) { ja = new JSONArray(); String imid, date, cat, buyer, seller, date2; imid = request.getParameter("imid"); date = request.getParameter("date"); date2 = request.getParameter("date2"); cat = request.getParameter("cat"); buyer = request.getParameter("buy"); seller = request.getParameter("sell"); System.out.println("imgid:" + imid); System.out.println("date:" + date); System.out.println("date2:" + date2); System.out.println("cat:" + cat); System.out.println("buyer:" + buyer); System.out.println("seller:" + seller); String sql = "SELECT SQL_CALC_FOUND_ROWS * FROM cart_has_images"; String where = ""; String tr = ""; if (imid.equals("0")) { imid = ""; } if (cat.equals("0")) { cat = ""; } if (buyer.equals("0")) { buyer = ""; } if (seller.equals("0")) { seller = ""; } if (!imid.equals("") && !imid.equals(null)) { if (where.equals("")) { where += " WHERE is_purchase!='0' AND is_purchase!='2' AND "; sql += where; } sql += " img_id='" + Integer.parseInt(imid) + "'"; if (!date.equals("") && !date.equals(null) && !date2.equals("") && !date2.equals(null) || !cat.equals("") && !cat.equals(null) || !buyer.equals("") && !buyer.equals(null) || !seller.equals("") && !seller.equals(null)) { sql += " AND "; } } if (!date.equals("") && !date.equals(null) && !date2.equals("") && !date2.equals(null)) { if (where.equals("")) { where += " WHERE is_purchase!='0' AND is_purchase!='2' AND "; sql += where; } String[] dt = date.split("-"); String[] dt2 = date2.split("-"); String orDate = dt[2] + "-" + dt[1] + "-" + dt[0]; String orDate2 = dt2[2] + "-" + dt2[1] + "-" + dt2[0]; System.out.println("date=" + orDate); sql += " date BETWEEN '" + orDate + "' AND '" + orDate2 + "'"; if (!cat.equals("") && !cat.equals(null) || !buyer.equals("") && !buyer.equals(null) || !seller.equals("") && !seller.equals(null)) { sql += " AND "; } } if (!cat.equals("") && !cat.equals(null)) { if (where.equals("")) { where += " WHERE is_purchase!='0' AND is_purchase!='2' AND "; sql += where; } sql += "img_id IN(SELECT images_id FROM images WHERE categories_category_id='" + cat + "')"; if (!buyer.equals("") && !buyer.equals(null) || !seller.equals("") && !seller.equals(null)) { sql += " AND "; } } if (!buyer.equals("") && !buyer.equals(null)) { if (where.equals("")) { where += " WHERE is_purchase!='0' AND is_purchase!='2' AND "; sql += where; } sql += "cart_id IN(SELECT cart_id FROM cart WHERE user_id='" + buyer + "')"; if (!seller.equals("") && !seller.equals(null)) { sql += " AND "; } } if (!seller.equals("") && !seller.equals(null)) { if (where.equals("")) { where += " WHERE is_purchase!='0' AND is_purchase!='2' AND "; sql += where; } sql += "img_id IN(SELECT images_id FROM images WHERE user_user_id='" + seller + "')"; } sql += " ORDER BY date DESC"; System.out.println("sql:" + sql); Images im; int i = 1; Categories cc = null; Cart ct = null; User buy = null; User Seller = null; try { PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql); ResultSet rs = ps.executeQuery(); while (rs.next()) { JSONObject jo = new JSONObject(); jo.put("cid", rs.getInt(2)); im = idi.getImageDetail(rs.getInt(2)); jo.put("title", im.getTitle()); jo.put("credit", rs.getInt(7)); cc = cadi.getCategory(im.getCategories_category_id()); jo.put("category", cc.getCategory()); jo.put("date", rs.getDate(6)); ct = cdi.getACart(rs.getInt(5)); buy = udi.getUser(ct.getUser_id()); Seller = udi.getUser(im.getUser_user_id()); jo.put("buyer", buy.getUser_name()); jo.put("seller", Seller.getUser_name()); ja.add(jo); } out.write("json=" + ja.toJSONString()); } catch (Exception e) { e.printStackTrace(); out.write("msg=Internal server error,Please try again later."); } } } else { out.write("msg=Internal server error,Please try again later."); } } catch (Exception e) { e.printStackTrace(); out.write("msg=Internal server error,Please try again later."); } }
From source file:com.ibm.bluemix.samples.PostgreSQLReportedErrors.java
/** * Retrieve the file information/*from w w w .jav a2 s . c om*/ * * @return JSON object with file information * @throws Exception TODO describe exception */ public JSONObject getFileInfo(String entryId) throws Exception { String sql = "SELECT * FROM reportedErrors WHERE entry_id = " + entryId; Connection connection = null; PreparedStatement statement = null; ResultSet results = null; try { connection = getConnection(); statement = connection.prepareStatement(sql); results = statement.executeQuery(); results.next(); JSONObject infoObject = new JSONObject(); infoObject.put("entry_id", Integer.toString(results.getInt("entry_id"))); infoObject.put("file_name", results.getString("file_name")); infoObject.put("s_language", results.getString("s_language")); infoObject.put("nlp_parser", results.getString("nlp_parser")); infoObject.put("upload_date", results.getDate("upload_date").toString()); infoObject.put("output_name", FilenameUtils.removeExtension(results.getString("file_name")) + ".xml"); return infoObject; } finally { if (results != null) { results.close(); } if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } }
From source file:Manager.managerFunctions.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from ww w . j av a2 s .c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //json to pass back to our ajax request JSONArray jsonArray = new JSONArray(); Connection con = null; try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); con = DriverManager .getConnection("jdbc:sqlserver://localhost;user=sa;password=nopw;allowMultiQueries=true"); Statement st = con.createStatement(); if (request.getParameter("func").equals("getRev")) { String query = "SELECT * FROM [MatchesFromAbove].[dbo].[DATE] WHERE DATEPART(month, DATE_TIME) = " + request.getParameter("month") + " AND DATEPART(year, DATE_TIME) = " + request.getParameter("year"); ResultSet rs = st.executeQuery(query); //loop through result set and create the json objects while (rs.next()) { JSONObject dateToAdd = new JSONObject(); dateToAdd.put("fee", rs.getString("Fee")); dateToAdd.put("time", rs.getDate("Date_Time").toString()); //add the json object that we're passing into the json array jsonArray.add(dateToAdd); } //set the content type of our response response.setContentType("application/json"); //printout prints it to our ajax call and it shows up there as data. you can use this data in the success function. PrintWriter printout = response.getWriter(); printout.print(jsonArray); printout.flush(); System.out.println("rev generated"); } if (request.getParameter("func").equals("getRevByDate")) { double totalRev = 0; String[] arrr = request.getParameter("date").split("/"); String query = "SELECT * FROM [MatchesFromAbove].[dbo].[DATE] WHERE DATEPART(month, DATE_TIME) = " + arrr[0] + " AND DATEPART(year, DATE_TIME) = " + arrr[2] + " AND DATEPART(day, DATE_TIME) = " + arrr[1]; ResultSet rs = st.executeQuery(query); //loop through result set and create the json objects while (rs.next()) { totalRev = totalRev + Double.parseDouble(rs.getString("Fee")); JSONObject dateToAdd = new JSONObject(); dateToAdd.put("fee", rs.getString("Fee")); dateToAdd.put("time", rs.getDate("Date_Time").toString()); //add the json object that we're passing into the json array jsonArray.add(dateToAdd); } JSONObject dateToAdd = new JSONObject(); dateToAdd.put("total", totalRev); jsonArray.add(dateToAdd); //set the content type of our response response.setContentType("application/json"); //printout prints it to our ajax call and it shows up there as data. you can use this data in the success function. PrintWriter printout = response.getWriter(); printout.print(jsonArray); printout.flush(); } if (request.getParameter("func").equals("getRevBySSN")) { double totalRev = 0; String ssn = request.getParameter("SSN"); String query = "SELECT *" + "FROM [MatchesFromAbove].[dbo].[DATE],[MatchesFromAbove].[dbo].[Profile]" + "WHERE ([MatchesFromAbove].[dbo].[DATE].Profile1Id = [MatchesFromAbove].[dbo].[Profile].ProfileId AND [MatchesFromAbove].[dbo].[Profile].OwnerSSN ='" + ssn + "') OR " + "([MatchesFromAbove].[dbo].[DATE].Profile2Id = [MatchesFromAbove].[dbo].[Profile].ProfileId AND [MatchesFromAbove].[dbo].[Profile].OwnerSSN ='" + ssn + "')"; ResultSet rs = st.executeQuery(query); //loop through result set and create the json objects while (rs.next()) { totalRev = totalRev + Double.parseDouble(rs.getString("Fee")); JSONObject dateToAdd = new JSONObject(); dateToAdd.put("fee", rs.getString("Fee")); dateToAdd.put("time", rs.getDate("Date_Time").toString()); //add the json object that we're passing into the json array jsonArray.add(dateToAdd); } JSONObject dateToAdd = new JSONObject(); dateToAdd.put("total", totalRev); jsonArray.add(dateToAdd); //set the content type of our response response.setContentType("application/json"); //printout prints it to our ajax call and it shows up there as data. you can use this data in the success function. PrintWriter printout = response.getWriter(); printout.print(jsonArray); printout.flush(); } if (request.getParameter("func").equals("getBestRep")) { try { st.execute( "CREATE VIEW booob AS SELECT [MatchesFromAbove].[dbo].[DATE].CustomerRep, SUM([MatchesFromAbove].[dbo].[DATE].Fee) AS sumFee FROM [MatchesFromAbove].[dbo].[DATE] GROUP BY [MatchesFromAbove].[dbo].[DATE].CustomerRep"); } catch (Exception e) { System.out.println("view exists "); st.execute("DROP VIEW booob"); st.execute( "CREATE VIEW booob AS SELECT [MatchesFromAbove].[dbo].[DATE].CustomerRep, SUM([MatchesFromAbove].[dbo].[DATE].Fee) AS sumFee FROM [MatchesFromAbove].[dbo].[DATE] GROUP BY [MatchesFromAbove].[dbo].[DATE].CustomerRep"); } String query = "SELECT * FROM booob"; ResultSet rs = st.executeQuery(query); //loop through result set and create the json objects Double max = 0.0; String name = ""; while (rs.next()) { double b = rs.getDouble("sumFee"); System.out.println(b + " " + rs.getString("CustomerRep")); if (b > max) { max = b; name = rs.getString("CustomerRep"); } } String query2 = "SELECT * FROM PERSON WHERE SSN = '" + name + "'"; ResultSet rs2 = st.executeQuery(query2); while (rs2.next()) { name = (rs2).getString("FirstName") + " " + (rs2).getString("LastName"); } //set the content type of our response response.setContentType("text/html"); //printout prints it to our ajax call and it shows up there as data. you can use this data in the success function. PrintWriter printout = response.getWriter(); printout.print("NAME: " + name + " Revenue Generated: $" + (long) (max * 100 + 0.5) / 100.0); printout.flush(); } if (request.getParameter("func").equals("getBestCust")) { ResultSet rs = st.executeQuery( " SELECT [MatchesFromAbove].[dbo].[PROFILE].OwnerSSN, SUM([MatchesFromAbove].[dbo].[DATE].Fee) AS sumFee " + " FROM [MatchesFromAbove].[dbo].[PROFILE], [MatchesFromAbove].[dbo].[DATE] " + " WHERE [MatchesFromAbove].[dbo].[DATE].Profile1Id = [MatchesFromAbove].[dbo].[PROFILE].ProfileId " + " GROUP BY OwnerSSN "); Map<String, Integer> my = new HashMap<String, Integer>(); while (rs.next()) { System.out.println("tack"); if (!my.containsKey(rs.getString("OwnerSSN"))) { my.put(rs.getString("OwnerSSN"), rs.getInt("sumFee")); } else { my.put(rs.getString("OwnerSSN"), (rs.getInt("sumFee")) + my.get(rs.getString("OwnerSSN"))); } System.out.println("2"); } ResultSet rs1 = st.executeQuery( " SELECT [MatchesFromAbove].[dbo].[PROFILE].OwnerSSN, SUM([MatchesFromAbove].[dbo].[DATE].Fee) AS sumFee " + " FROM [MatchesFromAbove].[dbo].[PROFILE], [MatchesFromAbove].[dbo].[DATE] " + " WHERE [MatchesFromAbove].[dbo].[DATE].Profile2Id = [MatchesFromAbove].[dbo].[PROFILE].ProfileId " + " GROUP BY OwnerSSN "); System.out.println("lalaland"); if (rs1 != null) while (rs1.next()) { System.out.println("tack"); if (!my.containsKey(rs1.getString("OwnerSSN"))) { my.put(rs1.getString("OwnerSSN"), rs1.getInt("sumFee")); } else { my.put(rs1.getString("OwnerSSN"), (rs1.getInt("sumFee")) + my.get(rs1.getString("OwnerSSN"))); } System.out.println("2"); } String ssn = ""; int max = 0; Iterator it = my.entrySet().iterator(); while (it.hasNext()) { Map.Entry pairs = (Map.Entry) it.next(); System.out.println(pairs.getKey() + " " + pairs.getValue()); if ((Integer) pairs.getValue() > max) { ssn = (String) pairs.getKey(); max = (Integer) pairs.getValue(); } it.remove(); // avoids a ConcurrentModificationException } String query = "SELECT * FROM PERSON WHERE SSN = '" + ssn + "'"; ResultSet t = st.executeQuery(query); t.next(); String name = t.getString("FirstName") + " " + t.getString("LastName"); System.out.println(my); //set the content type of our response response.setContentType("text/html"); //printout prints it to our ajax call and it shows up there as data. you can use this data in the success function. PrintWriter printout = response.getWriter(); printout.print("NAME: " + name + " Revenue Generated: $" + max); printout.flush(); } if (request.getParameter("func").equals("bestRatedCust")) { String query = "SELECT * FROM Customer C WHERE Rating > 3"; ResultSet rs = st.executeQuery(query); response.setContentType("text/html"); //printout prints it to our ajax call and it shows up there as data. you can use this data in the success function. PrintWriter printout = response.getWriter(); //loop through result set and create the json objects Double max = 0.0; String name = ""; String rating = ""; while (rs.next()) { name = rs.getString("SSN"); rating = rs.getString("Rating"); String query2 = "SELECT * FROM PERSON WHERE SSN = '" + name + "'"; ResultSet rs2 = st.executeQuery(query2); while (rs2.next()) { name = (rs2).getString("FirstName") + " " + (rs2).getString("LastName"); printout.print("<p>NAME: " + name + " Rating for Customer is: " + rating + "</p>"); } } } if (request.getParameter("func").equals("bestDateDays")) { String query = "SELECT CAST([MatchesFromAbove].[dbo].[DATE].Date_Time AS DATE) as Date, SUM([MatchesFromAbove].[dbo].[DATE].User1Rating+[MatchesFromAbove].[dbo].[DATE].User2Rating) as Score FROM [MatchesFromAbove].[dbo].[PROFILE], [MatchesFromAbove].[dbo].[DATE] GROUP BY CAST([MatchesFromAbove].[dbo].[DATE].Date_Time AS DATE) HAVING (SUM([MatchesFromAbove].[dbo].[DATE].User1Rating+[MatchesFromAbove].[dbo].[DATE].User2Rating) >= 1) ORDER BY Score DESC"; ResultSet rs = st.executeQuery(query); response.setContentType("text/html"); //printout prints it to our ajax call and it shows up there as data. you can use this data in the success function. PrintWriter printout = response.getWriter(); int i = 0; while (rs.next()) { i++; if (i == 4) { break; } printout.print("<p>RANK: " + i + "________ DAY FOR DATE: " + rs.getString("Date").substring(5) + "________ SCORE FOR THIS DAY: " + rs.getString("Score")); } //set the content type of our response printout.flush(); } if (request.getParameter("func").equals("mostActCust")) { String query; query = "SELECT [MatchesFromAbove].[dbo].[PROFILE].OwnerSSN, COUNT(*) AS numDates\n" + " FROM [MatchesFromAbove].[dbo].[PROFILE], [MatchesFromAbove].[dbo].[DATE]\n" + " WHERE [MatchesFromAbove].[dbo].[DATE].Profile1Id = [MatchesFromAbove].[dbo].[PROFILE].ProfileId\n" + " GROUP BY OwnerSSN\n" + " UNION ALL\n" + " SELECT [MatchesFromAbove].[dbo].[PROFILE].OwnerSSN, COUNT(*) AS numDates\n" + " FROM [MatchesFromAbove].[dbo].[PROFILE], [MatchesFromAbove].[dbo].[DATE]\n" + " WHERE [MatchesFromAbove].[dbo].[DATE].Profile2Id = [MatchesFromAbove].[dbo].[PROFILE].ProfileId\n" + " GROUP BY OwnerSSN"; System.out.println(query); ResultSet rs = st.executeQuery(query); Map<String, Integer> my = new HashMap<String, Integer>(); while (rs.next()) { if (!my.containsKey(rs.getString("OwnerSSN"))) { my.put(rs.getString("OwnerSSN"), 1); } else { my.put(rs.getString("OwnerSSN"), (Integer) my.get(rs.getString("OwnerSSN")) + 1); } } System.out.println(my); query = "SELECT [MatchesFromAbove].[dbo].[PROFILE].OwnerSSN, COUNT(*) AS numLikes\n" + " FROM [MatchesFromAbove].[dbo].[PROFILE], [MatchesFromAbove].[dbo].[LIKES]\n" + " WHERE [MatchesFromAbove].[dbo].[LIKES].LikerId = [MatchesFromAbove].[dbo].[PROFILE].ProfileId\n" + " GROUP BY OwnerSSN"; rs = st.executeQuery(query); while (rs.next()) { if (!my.containsKey(rs.getString("OwnerSSN"))) { my.put(rs.getString("OwnerSSN"), 1); } else { my.put(rs.getString("OwnerSSN"), (Integer) my.get(rs.getString("OwnerSSN")) + 1); } } response.setContentType("application/json"); //printout prints it to our ajax call and it shows up there as data. you can use this data in the success function. PrintWriter printout = response.getWriter(); // String s = " buns"; // while (rs.next()) { // System.out.println("bub"); // s = s+" "+ rs.getString("OwnerSSN"); // // } Iterator it = my.entrySet().iterator(); while (it.hasNext()) { Map.Entry pairs = (Map.Entry) it.next(); JSONObject dateToAdd = new JSONObject(); query = "SELECT * FROM PERSON WHERE SSN = '" + pairs.getKey() + "'"; ResultSet t = st.executeQuery(query); t.next(); dateToAdd.put("name", t.getString("FirstName") + " " + t.getString("LastName")); dateToAdd.put("level", pairs.getValue()); if ((Integer) pairs.getValue() > 1) jsonArray.add(dateToAdd); it.remove(); // avoids a ConcurrentModificationException } printout.print(jsonArray); //set the content type of our response printout.flush(); } con.close(); } catch (Exception e) { System.out.println(e.getMessage() + "managerFuncetionsClass"); if (con != null) try { con.close(); } catch (SQLException ex) { Logger.getLogger(managerFunctions.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.webpagebytes.wpbsample.database.WPBDatabase.java
private User getUserFromResultSet(ResultSet rs) throws SQLException { User user = new User(); user.setId(rs.getInt(1));// www . j av a 2 s . c om user.setUserName(rs.getString(2)); user.setEmail(rs.getString(3)); user.setPassword(rs.getString(4)); user.setOpen_date(rs.getDate(5)); user.setReceiveNewsletter(rs.getInt(6)); user.setConfirmEmailFlag(rs.getInt(7)); user.setConfirmEmailRandom(rs.getString(8)); user.setConfirmEmailDate(rs.getTimestamp(9)); return user; }
From source file:nl.tudelft.stocktrader.derby.DerbyCustomerDAO.java
public Account login(String userId, String password) throws DAOException { PreparedStatement selectCustomerProfileByUserId = null; PreparedStatement updateCustomerLogin = null; PreparedStatement selectCustomerLogin = null; try {/*from w w w.j av a2s. c om*/ selectCustomerProfileByUserId = sqlConnection.prepareStatement(SQL_SELECT_CUSTOMER_PROFILE_BY_USERID); selectCustomerProfileByUserId.setString(1, userId); ResultSet customerProfileRS = selectCustomerProfileByUserId.executeQuery(); if (customerProfileRS.next()) { try { String userPassword = customerProfileRS.getString(2); if (userPassword.equals(password)) { try { updateCustomerLogin = sqlConnection.prepareStatement(SQL_UPDATE_CUSTOMER_LOGIN); updateCustomerLogin.setString(1, userId); updateCustomerLogin.executeUpdate(); selectCustomerLogin = sqlConnection.prepareStatement(SQL_SELECT_CUSTOMER_LOGIN); selectCustomerLogin.setString(1, userId); ResultSet rs = selectCustomerLogin.executeQuery(); if (rs.next()) { try { Account accountData = new Account(rs.getInt(1), userId, StockTraderUtility.convertToCalendar(rs.getDate(2)), rs.getBigDecimal(3), rs.getInt(4), rs.getBigDecimal(5), StockTraderUtility.convertToCalendar(rs.getDate(6)), rs.getInt(7)); return accountData; } finally { try { rs.close(); } catch (SQLException e) { logger.debug("", e); } } } } catch (SQLException e) { throw new DAOException("", e); } finally { if (updateCustomerLogin != null) { try { updateCustomerLogin.close(); } catch (SQLException e) { logger.debug("", e); } } if (selectCustomerLogin != null) { try { selectCustomerLogin.close(); } catch (SQLException e) { logger.debug("", e); } } } } } finally { try { customerProfileRS.close(); } catch (SQLException e) { logger.debug("", e); } } } } catch (SQLException e) { throw new DAOException("", e); } finally { if (selectCustomerProfileByUserId != null) { try { selectCustomerProfileByUserId.close(); } catch (SQLException e) { logger.debug("", e); } } } return null; }
From source file:com.xinferin.dao.DAOCustomerImpl.java
@Override public Customer get(int customerId) { String sql = "SELECT * FROM customer WHERE id=" + customerId; return jdbcTemplate.query(sql, new ResultSetExtractor<Customer>() { @Override/*from www.j a v a 2s . c om*/ public Customer extractData(ResultSet rs) throws SQLException, DataAccessException { if (rs.next()) { Customer customer = new Customer(); customer.setId(rs.getInt("id")); customer.setFname(rs.getString("fname")); customer.setLname(rs.getString("lname")); customer.setCompany(rs.getString("company")); customer.setStreet(rs.getString("street")); customer.setCity(rs.getString("city")); customer.setState(rs.getString("state")); customer.setCountry(rs.getString("country")); customer.setPostcode(rs.getString("postcode")); customer.setTelephone(rs.getString("telephone")); customer.setEmail(rs.getString("email")); customer.setComments(rs.getString("comments")); customer.setDateAdded(rs.getDate("date_added")); return customer; } return null; } }); }
From source file:edu.uga.cs.fluxbuster.features.FeatureCalculator.java
/** * Calculates the cluster novelty feature for each cluster generated * on a specific run date.//from w w w . j a v a 2 s.com * * @param log_date the run date * @param window the number of days previous to use in feature calculation * @return a table of values where the keys are cluster ids and the values * are the feature values * @throws SQLException if there is an error calculating the feature values */ public Map<Integer, Double> calculateNoveltyFeature(Date log_date, int window) throws SQLException { HashMap<Integer, Double> retval = new HashMap<Integer, Double>(); ArrayList<Date> prevDates = getPrevDates(log_date, window); if (prevDates.size() > 0) { StringBuffer querybuf = new StringBuffer(); Formatter formatter = new Formatter(querybuf); String curdatestr = df.format(log_date); formatter.format(properties.getProperty(NOVELTY_QUERY1_1KEY), curdatestr, curdatestr, curdatestr, curdatestr); for (Date prevDate : prevDates) { formatter.format(" " + properties.getProperty(NOVELTY_QUERY1_2KEY) + " ", df.format(prevDate)); } formatter.format(properties.getProperty(NOVELTY_QUERY1_3KEY), curdatestr, curdatestr); ResultSet rs2 = null; Hashtable<Integer, Hashtable<String, Long>> new_resolved_ips = new Hashtable<Integer, Hashtable<String, Long>>(); try { rs2 = dbi.executeQueryWithResult(querybuf.toString()); while (rs2.next()) { int cluster_id = rs2.getInt(2); if (!new_resolved_ips.containsKey(cluster_id)) { new_resolved_ips.put(cluster_id, new Hashtable<String, Long>()); } String secondLevelDomainName = rs2.getString(1); long newips = rs2.getLong(3); Hashtable<String, Long> clustertable = new_resolved_ips.get(cluster_id); clustertable.put(secondLevelDomainName, newips); } } catch (Exception e) { if (log.isErrorEnabled()) { log.error(e); } } finally { if (rs2 != null && !rs2.isClosed()) { rs2.close(); } formatter.close(); } Hashtable<String, List<Integer>> numDays = new Hashtable<String, List<Integer>>(); for (Date prevDate : prevDates) { String prevDateStr = df.format(prevDate); querybuf = new StringBuffer(); formatter = new Formatter(querybuf); formatter.format(properties.getProperty(NOVELTY_QUERY2KEY), curdatestr, prevDateStr, curdatestr, prevDateStr); ResultSet rs3 = null; try { rs3 = dbi.executeQueryWithResult(querybuf.toString()); while (rs3.next()) { String sldn = rs3.getString(1); if (!numDays.containsKey(sldn)) { numDays.put(sldn, new ArrayList<Integer>()); } Date pd = rs3.getDate(2); DateTime start = new DateTime(pd.getTime()); DateTime end = new DateTime(log_date.getTime()); Days d = Days.daysBetween(start, end); int diffDays = d.getDays(); numDays.get(sldn).add(diffDays); } } catch (Exception e) { if (log.isErrorEnabled()) { log.error(e); } } finally { if (rs3 != null && !rs3.isClosed()) { rs3.close(); } formatter.close(); } } Hashtable<Integer, List<Float>> clusterValues = new Hashtable<Integer, List<Float>>(); for (int clusterID : new_resolved_ips.keySet()) { clusterValues.put(clusterID, new ArrayList<Float>()); Hashtable<String, Long> sldnValues = new_resolved_ips.get(clusterID); for (String sldn : sldnValues.keySet()) { if (numDays.keySet().contains(sldn)) { long newIPCount = sldnValues.get(sldn); float f = ((float) newIPCount) / Collections.max(numDays.get(sldn)); clusterValues.get(clusterID).add(f); } } } for (int clusterID : clusterValues.keySet()) { if (clusterValues.get(clusterID) == null) { //I dont think it is possible for this to ever be true retval.put(clusterID, null); } else { double sum = 0; for (double d : clusterValues.get(clusterID)) { sum += d; } double val = 0; if (clusterValues.get(clusterID).size() > 0) { val = sum / clusterValues.get(clusterID).size(); } retval.put(clusterID, val); } } } return retval; }