List of usage examples for java.sql Timestamp toString
@SuppressWarnings("deprecation") public String toString()
From source file:ru.org.linux.spring.DelIPController.java
/** * ? ip //from w ww . j a v a2s .co m * @param request http ? (? ? ?) * @param reason ? * @param ip ip ? * @param time ? ? (hour, day, 3day) * @return ? ? ? * @throws Exception - ??? */ @RequestMapping(value = "/delip.jsp", method = RequestMethod.POST) public ModelAndView delIp(HttpServletRequest request, @RequestParam("reason") String reason, @RequestParam("ip") String ip, @RequestParam("time") String time) throws Exception { Map<String, Object> params = new HashMap<>(); Template tmpl = Template.getTemplate(request); if (!tmpl.isModeratorSession()) { throw new AccessViolationException("Not moderator"); } Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); if ("hour".equals(time)) { calendar.add(Calendar.HOUR_OF_DAY, -1); } else if ("day".equals(time)) { calendar.add(Calendar.DAY_OF_MONTH, -1); } else if ("3day".equals(time)) { calendar.add(Calendar.DAY_OF_MONTH, -3); } else { throw new UserErrorException("Invalid count"); } Timestamp ts = new Timestamp(calendar.getTimeInMillis()); params.put("message", "? ?? ? " + ts.toString() + " ? IP " + ip + "<br>"); User moderator = tmpl.getCurrentUser(); DeleteCommentResult deleteResult = commentService.deleteCommentsByIPAddress(ip, ts, moderator, reason); params.put("topics", deleteResult.getDeletedTopicIds().size()); // - params.put("deleted", deleteResult.getDeleteInfo()); for (int topicId : deleteResult.getDeletedTopicIds()) { searchQueueSender.updateMessage(topicId, true); } searchQueueSender.updateComment(deleteResult.getDeletedCommentIds()); return new ModelAndView("delip", params); }
From source file:bookUtilities.PopulateMyBooksServlet.java
private JSONArray getUserBooks(String email, JSONArray fileTypes) { String query;/*ww w .ja v a 2s . c o m*/ JSONArray jsons = new JSONArray(); try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost;user=sa;password=nopw"); Statement st = con.createStatement(); query = "SELECT Book.*, checkedBooks.ExpirationDate " + "FROM [HardCover].[dbo].[Book] Book, [HardCover].[dbo].[RegisteredUser] RegisteredUser, [HardCover].[dbo].[CheckedOutBook] checkedBooks, [HardCover].[dbo].[Person] P " + "WHERE Book.BookUuid = checkedBooks.BookId AND checkedBooks.RegisteredUserId = RegisteredUser.RegisteredUserId AND P.PersonUuid = RegisteredUser.RegisteredUserId " + " AND P.Email = '" + email + "' AND checkedBooks.Expired = 0"; ResultSet rs = st.executeQuery(query); /* TODO output your page here. You may use following sample code. */ while (rs.next()) { JSONObject bookToAdd = new JSONObject(); JSONArray fileTypesArray = new JSONArray(); Statement st2 = con.createStatement(); Statement st3 = con.createStatement(); Timestamp timeStamp = rs.getTimestamp("ExpirationDate"); String timeString = timeStamp.toString(); String bookId = rs.getString("BookUuid"); query = "SELECT AuthorName " + "FROM [HardCover].[dbo].[Author] " + "WHERE BookId = '" + bookId + "';"; ResultSet rs2 = st2.executeQuery(query); rs2.next(); query = "SELECT FileType, DownloadLink " + "FROM [HardCover].[dbo].[BookFileType] " + "WHERE BookId = '" + bookId + "'"; ResultSet rs3 = st3.executeQuery(query); while (rs3.next()) { JSONObject fileTypeToAdd = new JSONObject(); fileTypeToAdd.put("fileType", rs3.getString("FileType")); fileTypeToAdd.put("downloadLink", rs3.getString("DownLoadLink")); fileTypesArray.add(fileTypeToAdd); } fileTypes.add(fileTypesArray); bookToAdd.put("expirationDate", timeString); bookToAdd.put("author", rs2.getString("AuthorName")); bookToAdd.put("title", rs.getString("Title")); bookToAdd.put("cover", rs.getString("Cover")); bookToAdd.put("dateAdded", rs.getString("DateAdded")); bookToAdd.put("bookId", rs.getString("BookUuid")); jsons.add(bookToAdd); } } catch (Exception e) { System.out.println(e.getMessage()); } return jsons; }
From source file:uk.ac.kcl.partitioners.RealtimeTimeStampAndPKRangePartitioner.java
private ScheduledPartitionParams scanForNewRecords(Timestamp jobStartTimeStamp) { ScheduledPartitionParams result = null; logger.info("No new data found in processing period " + String.valueOf(jobStartTimeStamp.toString()) + " to " + getEndTimeStamp(jobStartTimeStamp).toString() + ". Commencing scan ahead"); Timestamp newJobStartTimeStamp = batchJobUtils.checkForNewRecordsBeyondConfiguredProcessingPeriod(table, jobStartTimeStamp, timeStamp); if (newJobStartTimeStamp == null) { logger.info("Database appears to be synched as far as " + jobStartTimeStamp.toString() + ". " + "Checking again on next run"); informJobCompleteListenerOfLastDate(jobStartTimeStamp); } else {/*from w w w . j av a 2s .c om*/ logger.info("New data found! Generating partitions from " + newJobStartTimeStamp.toString() + " inclusive."); result = getParams(newJobStartTimeStamp, true); } return result; }
From source file:cz.zcu.kiv.eegdatabase.logic.csv.SimpleCSVFactory.java
/** * Get date of birth/* ww w . j ava 2 s . co m*/ * * @param date - date of birth * @return only date without time */ private String getDateOfBirth(Timestamp date) { String[] dateOfBirth = null; String noDate = "-"; if (date != null) { dateOfBirth = date.toString().split(" "); return dateOfBirth[0]; } return noDate; }
From source file:uk.ac.kcl.partitioners.RealtimeTimeStampAndPKRangePartitioner.java
private String getStartTimeExclusiveSqlString(String sql, Timestamp jobStartTimeStamp, Timestamp jobEndTimeStamp) { sql = sql + " WHERE CAST (" + timeStamp + " as " + env.getProperty("dbmsToJavaSqlTimestampType") + " ) " + "> CAST ('" + jobStartTimeStamp.toString() + "' as " + env.getProperty("dbmsToJavaSqlTimestampType") + " ) " + " AND CAST (" + timeStamp + " as " + env.getProperty("dbmsToJavaSqlTimestampType") + " ) " + " <= CAST ('" + jobEndTimeStamp.toString() + "' as " + env.getProperty("dbmsToJavaSqlTimestampType") + " ) ) t1"; return sql;// ww w . ja va2 s . c om }
From source file:uk.ac.kcl.partitioners.RealtimeTimeStampAndPKRangePartitioner.java
private String getStartTimeInclusiveSqlString(String sql, Timestamp jobStartTimeStamp, Timestamp jobEndTimeStamp) { sql = sql + " WHERE CAST (" + timeStamp + " as " + env.getProperty("dbmsToJavaSqlTimestampType") + " ) " + "\nBETWEEN CAST ('" + jobStartTimeStamp.toString() + "' as " + env.getProperty("dbmsToJavaSqlTimestampType") + " ) " + " AND CAST ('" + jobEndTimeStamp.toString() + "' as " + env.getProperty("dbmsToJavaSqlTimestampType") + " ) " + " ) t1"; return sql;/*from ww w . j a v a 2 s.c om*/ }
From source file:com.hihframework.core.utils.DateUtils.java
public static String getCalendarModel(java.sql.Timestamp date) { if (date != null) { return getHours(date.toString()); } else {/*from ww w . j av a 2 s .com*/ return null; } }
From source file:isl.FIMS.servlet.imports.ImportVocabulary.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.initVars(request); String username = getUsername(request); Config conf = new Config("AdminVoc"); response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); StringBuilder xml = new StringBuilder( this.xmlStart(this.topmenu, username, this.pageTitle, this.lang, "", request)); String file = request.getParameter("file"); if (ServletFileUpload.isMultipartContent(request)) { // configures some settings String filePath = this.export_import_Folder; java.util.Date date = new java.util.Date(); Timestamp t = new Timestamp(date.getTime()); String currentDir = filePath + t.toString().replaceAll(":", ""); File saveDir = new File(currentDir); if (!saveDir.exists()) { saveDir.mkdir();// ww w .j a v a2 s .c om } DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD); factory.setRepository(saveDir); ServletFileUpload upload = new ServletFileUpload(factory); upload.setSizeMax(REQUEST_SIZE); // constructs the directory path to store upload file String uploadPath = currentDir; try { // parses the request's content to extract file data List formItems = upload.parseRequest(request); Iterator iter = formItems.iterator(); // iterates over form's fields File storeFile = null; while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); // processes only fields that are not form fields if (!item.isFormField()) { String fileName = new File(item.getName()).getName(); filePath = uploadPath + File.separator + fileName; storeFile = new File(filePath); // saves the file on disk item.write(storeFile); } } ArrayList<String> content = Utils.readFile(storeFile); DMSConfig vocConf = new DMSConfig(this.DBURI, this.systemDbCollection + "Vocabulary/", this.DBuser, this.DBpassword); Vocabulary voc = new Vocabulary(file, this.lang, vocConf); String[] terms = voc.termValues(); for (int i = 0; i < content.size(); i++) { String addTerm = content.get(i); if (!Arrays.asList(terms).contains(addTerm)) { voc.addTerm(addTerm); } } Utils.deleteDir(currentDir); response.sendRedirect("AdminVoc?action=list&file=" + file + "&menuId=AdminVoc"); } catch (Exception ex) { } } xml.append("<FileName>").append(file).append("</FileName>\n"); xml.append("<EntityType>").append("AdminVoc").append("</EntityType>\n"); xml.append(this.xmlEnd()); String xsl = conf.IMPORT_Vocabulary; try { XMLTransform xmlTrans = new XMLTransform(xml.toString()); xmlTrans.transform(out, xsl); } catch (DMSException e) { e.printStackTrace(); } out.close(); }
From source file:NoSQLvsSQL.SqlDB.java
public Date getRandomDate() throws ParseException { long offset = Timestamp.valueOf("2000-01-01 00:00:00").getTime(); long end = Timestamp.valueOf("2016-01-01 00:00:00").getTime(); long diff = end - offset + 1; Timestamp rand = new Timestamp(offset + (long) (Math.random() * diff)); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd"); return simpleDateFormat.parse(rand.toString()); }
From source file:org.xmlactions.mapping.bean_to_xml.PopulatorFromTimestamp.java
public Element performAttributeAction(List<KeyValue> keyvalues, BeanToXml beanToXml, Element parent, Object object, String namespacePrefix, String attributeName, String beanRef) { if (object instanceof Timestamp) { Timestamp timestamp = (Timestamp) object; String output;/*from w w w .j a v a 2s . c o m*/ String format = getKeyValue(keyvalues, MappingConstants.TIME_FORMAT); if (StringUtils.isNotEmpty(format)) { output = DateFormatUtils.format(timestamp.getTime(), format); } else { output = timestamp.toString(); } Element attribute = BeanToXmlUtils.addAttribute(parent, namespacePrefix, attributeName, output); return attribute; } else { throw new IllegalArgumentException("The object parameter must be a " + Timestamp.class.getName() + " not [" + object.getClass().getName() + "]"); } }