List of usage examples for java.sql Timestamp getTime
public long getTime()
From source file:com.wabacus.system.datatype.CTimestampType.java
public Object getColumnValue(ResultSet rs, int iindex, AbsDatabaseType dbtype) throws SQLException { java.sql.Timestamp cts = rs.getTimestamp(iindex); if (cts == null) return null; Calendar cd = Calendar.getInstance(); cd.setTimeInMillis(cts.getTime()); return cd;/* w w w . jav a 2s. c o m*/ }
From source file:org.group2.webapp.web.mvc.ctrl.UploadController.java
@PostMapping("/multiupload") public @ResponseBody String uploadMultipleFileHandler(@RequestParam("evidenceFiles") MultipartFile[] files) { // if (files.length != names.length) { // return "Mandatory information missing"; // }/*from w ww . j av a 2s. c om*/ String name; String message = ""; for (int i = 0; i < files.length; i++) { MultipartFile file = files[i]; try { byte[] bytes = file.getBytes(); long time = System.currentTimeMillis(); java.sql.Timestamp timestmp = new java.sql.Timestamp(time); name = "evidence" + i + "_" + timestmp.getTime(); logger.info(FilenameUtils.getExtension(file.getOriginalFilename())); // Creating the directory to store file String actualPath = servletContext.getRealPath(""); String fileLocation = actualPath + File.separator + "evidents"; File dir = new File(fileLocation); if (!dir.exists()) { dir.mkdirs(); } // Create the file on server File serverFile = new File(dir.getAbsolutePath() + File.separator + name); BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile)); stream.write(bytes); stream.close(); logger.info("Saved to: " + serverFile.getAbsolutePath()); message = message + "You successfully uploaded file=" + name; } catch (Exception e) { return "You failed to upload evidents" + e.getMessage(); } } return message; }
From source file:com.impetus.kundera.property.accessor.SQLTimestampAccessor.java
@Override public String toString(Object object) { Timestamp timeStamp = (Timestamp) object; if (timeStamp == null) { return null; }//from www . j av a 2 s .c o m return String.valueOf(timeStamp.getTime()); }
From source file:org.apdplat.superword.tools.MySQLUtils.java
public static List<UserUrl> getHistoryUserUrlsFromDatabase(String userName) { List<UserUrl> userUrls = new ArrayList<>(); String sql = "select id,url,date_time from user_url where user_name=?"; Connection con = getConnection(); if (con == null) { return userUrls; }/*from ww w. ja v a 2s . c om*/ PreparedStatement pst = null; ResultSet rs = null; try { pst = con.prepareStatement(sql); pst.setString(1, userName); rs = pst.executeQuery(); while (rs.next()) { int id = rs.getInt(1); String url = rs.getString(2); Timestamp timestamp = rs.getTimestamp(3); UserUrl userUrl = new UserUrl(); userUrl.setId(id); userUrl.setUrl(url); userUrl.setDateTime(new java.util.Date(timestamp.getTime())); userUrl.setUserName(userName); userUrls.add(userUrl); } } catch (SQLException e) { LOG.error("", e); } finally { close(con, pst, rs); } return userUrls; }
From source file:uk.ac.kcl.rowmappers.DocumentRowMapper.java
private void mapDBFields(Document doc, ResultSet rs) throws SQLException, IOException { //add additional query fields for ES export ResultSetMetaData meta = rs.getMetaData(); int colCount = meta.getColumnCount(); for (int col = 1; col <= colCount; col++) { Object value = rs.getObject(col); if (value != null) { String colLabel = meta.getColumnLabel(col).toLowerCase(); if (!fieldsToIgnore.contains(colLabel)) { DateTime dateTime;/*from w ww.ja va2s . com*/ //map correct SQL time types switch (meta.getColumnType(col)) { case 91: Date dt = (Date) value; dateTime = new DateTime(dt.getTime()); doc.getAssociativeArray().put(meta.getColumnLabel(col).toLowerCase(), eSCompatibleDateTimeFormatter.print(dateTime)); break; case 93: Timestamp ts = (Timestamp) value; dateTime = new DateTime(ts.getTime()); doc.getAssociativeArray().put(meta.getColumnLabel(col).toLowerCase(), eSCompatibleDateTimeFormatter.print(dateTime)); break; default: doc.getAssociativeArray().put(meta.getColumnLabel(col).toLowerCase(), rs.getString(col)); break; } } } //map binary content from FS or database if required (as per docman reader) if (value != null && meta.getColumnLabel(col).equalsIgnoreCase(binaryContentFieldName)) { switch (binaryContentSource) { case "database": doc.setBinaryContent(rs.getBytes(col)); break; case "fileSystemWithDBPath": Resource resource = context.getResource(pathPrefix + rs.getString(col)); doc.setBinaryContent(IOUtils.toByteArray(resource.getInputStream())); break; default: break; } } } }
From source file:com.idega.bedework.bussiness.impl.BedeworkDateServiceBean.java
@Override public BwDateTime convertDate(Timestamp date) { if (date == null) { return null; }// w w w .j a v a 2 s .com return convertDate(date.getTime()); }
From source file:org.apdplat.superword.tools.MySQLUtils.java
public static List<UserBook> getHistoryUserBooksFromDatabase(String userName) { List<UserBook> userBooks = new ArrayList<>(); String sql = "select id,book,date_time from user_book where user_name=?"; Connection con = getConnection(); if (con == null) { return userBooks; }//from ww w . j a v a 2 s .c o m PreparedStatement pst = null; ResultSet rs = null; try { pst = con.prepareStatement(sql); pst.setString(1, userName); rs = pst.executeQuery(); while (rs.next()) { int id = rs.getInt(1); String book = rs.getString(2); Timestamp timestamp = rs.getTimestamp(3); UserBook userBook = new UserBook(); userBook.setId(id); userBook.setBook(book); userBook.setDateTime(new java.util.Date(timestamp.getTime())); userBook.setUserName(userName); userBooks.add(userBook); } } catch (SQLException e) { LOG.error("", e); } finally { close(con, pst, rs); } return userBooks; }
From source file:org.apdplat.superword.tools.MySQLUtils.java
public static List<UserText> getHistoryUserTextsFromDatabase(String userName) { List<UserText> userTexts = new ArrayList<>(); String sql = "select id,text,date_time from user_text where user_name=?"; Connection con = getConnection(); if (con == null) { return userTexts; }// w w w . jav a 2s . c o m PreparedStatement pst = null; ResultSet rs = null; try { pst = con.prepareStatement(sql); pst.setString(1, userName); rs = pst.executeQuery(); while (rs.next()) { int id = rs.getInt(1); String text = rs.getString(2); Timestamp timestamp = rs.getTimestamp(3); UserText userText = new UserText(); userText.setId(id); userText.setText(text); userText.setDateTime(new java.util.Date(timestamp.getTime())); userText.setUserName(userName); userTexts.add(userText); } } catch (SQLException e) { LOG.error("", e); } finally { close(con, pst, rs); } return userTexts; }
From source file:org.apdplat.superword.tools.MySQLUtils.java
public static List<UserWord> getHistoryUserWordsFromDatabase(String userName) { List<UserWord> userWords = new ArrayList<>(); String sql = "select id,word,date_time from user_word where user_name=? order by date_time desc"; Connection con = getConnection(); if (con == null) { return userWords; }/*from w w w .jav a2s .c om*/ PreparedStatement pst = null; ResultSet rs = null; try { pst = con.prepareStatement(sql); pst.setString(1, userName); rs = pst.executeQuery(); while (rs.next()) { int id = rs.getInt(1); String word = rs.getString(2); Timestamp timestamp = rs.getTimestamp(3); UserWord userWord = new UserWord(); userWord.setId(id); userWord.setWord(word); userWord.setDateTime(new java.util.Date(timestamp.getTime())); userWord.setUserName(userName); userWords.add(userWord); } } catch (SQLException e) { LOG.error("", e); } finally { close(con, pst, rs); } return userWords; }
From source file:com.mothsoft.alexis.rest.dataset.v1.impl.DataSetResourceImpl.java
@Override public List<DataSetPoint> findAndAggregatePointsGroupedByUnit(Long dataSetId, Timestamp startDate, Timestamp endDate, String units) { final TimeUnits unitEnum; if (units == null) { final long duration = endDate.getTime() - startDate.getTime(); if (duration >= DateConstants.ONE_WEEK_IN_MILLISECONDS) { unitEnum = TimeUnits.DAY;/*from w w w . j ava 2s . c om*/ } else { unitEnum = TimeUnits.HOUR; } } else { unitEnum = TimeUnits.valueOf(units); } final List<com.mothsoft.alexis.domain.DataSetPoint> pointDomains = this.service .findAndAggregatePointsGroupedByUnit(dataSetId, startDate, endDate, unitEnum); return toDto(pointDomains); }