List of usage examples for java.sql Date getTime
public long getTime()
From source file:stg.utils.immutable.Day.java
/** * Sets the current day to a new day.//from w ww.j a va2s .c om * * @param psdt * java.sql.Date */ public static Day createDay(java.sql.Date psdt) { return Day.createDay(psdt.getTime()); }
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 w w . j av a 2 s .c o m //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:solarrecorder.SolarRecorder.java
private void sendSolarUpdate() { String dbString = "jdbc:mysql://localhost:3306/Solar"; try {// www .j av a 2 s . c om Connection con = DriverManager.getConnection(dbString, "colin", "Quackquack1"); Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); String SQL = "SELECT * FROM Production"; ResultSet rs = stmt.executeQuery(SQL); rs.moveToInsertRow(); getData(); java.util.Date now = new java.util.Date(); rs.updateDate("Day", new Date(now.getTime())); rs.updateTime("Time", new Time(now.getTime())); for (Object evp : envoyData) { switch (((EnvoyData) evp).getName()) { case "Currently": rs.updateDouble("Current", extractCurrent(((EnvoyData) evp).getValue())); break; case "Today": rs.updateDouble("Today", extractToday(((EnvoyData) evp).getValue())); break; case "Number of Microinverters Online": rs.updateInt("Inverters", Integer.parseInt(((EnvoyData) evp).getValue())); break; } } rs.insertRow(); stmt.close(); rs.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.projectforge.rest.converter.UTCDateTypeAdapter.java
@Override public synchronized Date deserialize(final JsonElement jsonElement, final Type type, final JsonDeserializationContext jsonDeserializationContext) { try {/* w w w .j av a 2 s . c o m*/ synchronized (dateFormatter) { final String element = jsonElement.getAsString(); if (element == null) { return null; } if (StringUtils.isNumeric(element) == true) { final Date date = new Date(Long.parseLong(element)); return date; } final java.util.Date date = dateFormatter.parse(element); return new Date(date.getTime()); } } catch (final ParseException e) { throw new JsonSyntaxException(jsonElement.getAsString(), e); } }
From source file:com.livgrhm.kansas.resources.AuthResource.java
@GET @Timed// ww w . ja v a 2 s.c om public AuthenticationResult doAuth(@QueryParam("email") String email, @QueryParam("hash") String hash, @Context HttpServletRequest req) { User user = this.dao.getUserByEmail(email); System.out.println("USER!!!! " + user.getEmail()); if (user == null) { LOGGER.info(" auth notFound " + email); return new AuthenticationResult("F"); } if (user.getUserStatus().equals("D")) { LOGGER.info(" auth isDisabled " + email); return new AuthenticationResult("F"); } if (user.getUserStatus().equals("N")) { if (DigestUtils.sha256Hex((email.toUpperCase() + user.getUserPasswordHash())).equals(hash)) { LOGGER.info(" auth new " + email); return new AuthenticationResult("N"); } else { LOGGER.info(" auth badPassword " + email); return new AuthenticationResult("F"); } } if (user.getUserStatus().equals("V")) { LOGGER.info(" auth notVerified " + email); return new AuthenticationResult("V"); } if (user.getUserPasswordHash().equals(hash)) { LOGGER.info(" auth successful " + email); // create new hash based on the password and a timestamp, and update the user table accordingly. // future data requests will then be tested against this authorisation hash (i.e. an authorisation credential). // the timestamp is to ensure existing credentials expire after (CURRENTLY) 24 hrs java.sql.Date now = new java.sql.Date((new java.util.Date()).getTime()); String timestampHash = DigestUtils.sha256Hex(user.getUserPasswordHash() + now.getTime()); this.dao.setUserAuthHash(user.getUserId(), timestampHash, now, req.getRemoteAddr()); addToAuthList(user.getEmail(), timestampHash, now, req.getRemoteAddr()); return new AuthenticationResult("Y", user.getUserId(), timestampHash, user.getUserStatus()); } else { LOGGER.info(" auth badPassword " + email); if (user.getUserFailedLogons() > 3) { // already 3 failed attempts, so disable the account user.setUserStatus("L"); this.dao.updateUserLockAccount(user.getUserId()); } this.dao.updateFailedLogonCount(user.getUserId()); return new AuthenticationResult("F"); } }
From source file:org.kuali.kfs.coa.batch.dataaccess.impl.AccountingPeriodFiscalYearMakerImpl.java
/** * Adds one year to the given date// w w w. j a v a 2 s . com * * @param inDate date to increment * @return Date incoming date plus one year */ protected java.sql.Date addYearToDate(Date inDate) { GregorianCalendar currentCalendarDate = new GregorianCalendar(); currentCalendarDate.clear(); currentCalendarDate.setTimeInMillis(inDate.getTime()); currentCalendarDate.add(GregorianCalendar.YEAR, 1); return new Date(currentCalendarDate.getTimeInMillis()); }
From source file:org.psystems.dicom.browser.server.stat.StatClientRequestsChartServlet.java
/** * @param connection// ww w . j a v a 2 s . c om * @param series * @param metrica * @param timeBegin * @param timeEnd * @param dataset * @throws SQLException */ private void getMetrics(Connection connection, String series, String metrica, long timeBegin, long timeEnd, DefaultCategoryDataset dataset) throws SQLException { PreparedStatement stmt = null; try { // String dateStr = format.format(calendar.getTime()); // System.out.println("!!! " + dateStr); SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy"); stmt = connection.prepareStatement("SELECT METRIC_VALUE_LONG, METRIC_DATE" + " FROM WEBDICOM.DAYSTAT WHERE METRIC_NAME = ? and " + " METRIC_DATE BETWEEN ? AND ? "); stmt.setString(1, metrica); stmt.setDate(2, new java.sql.Date(timeBegin)); stmt.setDate(3, new java.sql.Date(timeEnd)); ResultSet rs = stmt.executeQuery(); while (rs.next()) { long value = rs.getLong("METRIC_VALUE_LONG"); Date date = rs.getDate("METRIC_DATE"); String dateStr = format.format(date.getTime()); String category = dateStr; dataset.addValue(value, series, category); // System.out.println("!!!! " + metrica + "=" + dateStr + "=" // + value); } rs.close(); } finally { if (stmt != null) stmt.close(); } }
From source file:com.livgrhm.kansas.resources.UserResource.java
@POST @Timed/*from ww w . j a va 2 s. co m*/ public Response addUser(User user) { // POST e.g. '{"firstName":"test", "lastName":"tester", "email":"test", "userStatus":"N", "userPasswordHash":"1234"}' // Create authentication hash java.sql.Date now = new java.sql.Date((new java.util.Date()).getTime()); String userAuthHash = DigestUtils.sha256Hex(user.getUserPasswordHash() + now.getTime()); user.setUserAuthHash(userAuthHash); user.setUserAuthTimestamp(now); try { int userId = this.dao.createUser(user.getFirstName(), user.getLastName(), user.getEmail(), user.getUserStatus(), user.getUserPasswordHash(), user.getUserAuthHash(), user.getUserAuthTimestamp()); user.setUserId(userId); return Response.status(Response.Status.CREATED).entity(user).build(); } catch (Exception e) { System.out.println("Exception creating user: " + e.getMessage()); return Response.status(Response.Status.NOT_IMPLEMENTED).build(); } }
From source file:su90.mybatisdemo.dao.EmployeesMapperTest.java
@Test(groups = { "find" }) public void testFindByRawProperties02() { try {/*from w ww.j av a 2 s. c om*/ EmployeesMapper.EmployeeQuery sampleEQ = new EmployeesMapper.EmployeeQuery(); SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); java.util.Date startUtilDate = formatter.parse("20040101"); java.util.Date endUtilDate = formatter.parse("20050101"); sampleEQ.setStartHiredate(new Date(startUtilDate.getTime())); sampleEQ.setEndHiredate(new Date(endUtilDate.getTime())); List<Employee> result = employeesMapper.findByRawProperties(sampleEQ); assertEquals(result.size(), 10); } catch (ParseException ex) { assertTrue(false); } }
From source file:org.psystems.dicom.browser.server.stat.StatDailyLoadChartServlet.java
/** * @param connection/*from w w w.j a va 2 s .c o m*/ * @param series * @param metrica * @param timeBegin * @param timeEnd * @param dataset * @throws SQLException */ private void getMetrics(Connection connection, String series, String metrica, long timeBegin, long timeEnd, DefaultCategoryDataset dataset) throws SQLException { PreparedStatement stmt = null; try { // String dateStr = format.format(calendar.getTime()); // System.out.println("!!! " + dateStr); SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy"); stmt = connection.prepareStatement("SELECT METRIC_VALUE_LONG, METRIC_DATE" + " FROM WEBDICOM.DAYSTAT WHERE METRIC_NAME = ? and " + " METRIC_DATE BETWEEN ? AND ? "); stmt.setString(1, metrica); stmt.setDate(2, new java.sql.Date(timeBegin)); stmt.setDate(3, new java.sql.Date(timeEnd)); ResultSet rs = stmt.executeQuery(); while (rs.next()) { long value = rs.getLong("METRIC_VALUE_LONG") / 1000; Date date = rs.getDate("METRIC_DATE"); String dateStr = format.format(date.getTime()); String category = dateStr; dataset.addValue(value, series, category); // System.out.println("!!!! ALL_DCM_SIZE="+dateStr+"="+value); } rs.close(); } finally { if (stmt != null) stmt.close(); } }