Java Code Examples for java.sql.Date

The following are top voted examples for showing how to use java.sql.Date. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: the-vigilantes   File: StatementRegressionTest.java   Source Code and License 6 votes vote down vote up
/**
 * Tests fix for BUG#54095 - Unnecessary call in newSetTimestampInternal.
 *
 * This bug was fixed as a consequence of the patch for Bug#71084.
 *
 * @throws Exception
 *             if the test fails.
 */
public void testBug54095() throws Exception {
    Connection testConn = getConnectionWithProps("useLegacyDatetimeCode=false");

    Calendar testCal = Calendar.getInstance();
    java.util.Date origDate = testCal.getTime();

    PreparedStatement testPstmt = testConn.prepareStatement("SELECT ?");
    testPstmt.setTimestamp(1, new Timestamp(0), testCal);
    assertEquals("Calendar object shouldn't have changed after PreparedStatement.setTimestamp().", origDate, testCal.getTime());

    ResultSet testRs = testPstmt.executeQuery();
    testRs.next();
    assertEquals("Calendar object shouldn't have changed after PreparedStatement.executeQuery().", origDate, testCal.getTime());

    testRs.getTimestamp(1, testCal);
    assertEquals("Calendar object shouldn't have changed after ResultSet.getTimestamp().", origDate, testCal.getTime());

    testRs.close();
    testPstmt.close();
    testConn.close();
}
 
Example 2
Project: eXperDB-DB2PG   File: DataAdapter.java   Source Code and License 6 votes vote down vote up
private  void PreparedStmtSetValue(CallableStatement cStmt, int idx, Object obj) throws SQLException{
	if (obj instanceof String) {
		pStmt.setString(idx, (String) obj);
	} else if(obj instanceof Integer){
		pStmt.setInt(idx, (Integer) obj);
	} else if(obj instanceof BigDecimal){
			pStmt.setBigDecimal(idx, (BigDecimal) obj);
	} else if(obj instanceof Double){
		pStmt.setDouble(idx, (Double) obj);
	} else if(obj instanceof Date){
		pStmt.setDate(idx, (Date) obj);
	} else if(obj instanceof byte[]){
		pStmt.setBytes(idx, (byte[]) obj);			
	} else{
		pStmt.setObject(idx, obj);
	}
}
 
Example 3
Project: aliyun-maxcompute-data-collectors   File: HCatalogExportTest.java   Source Code and License 6 votes vote down vote up
public void testDateTypesToBigInt() throws Exception {
  final int TOTAL_RECORDS = 1 * 10;
  long offset = TimeZone.getDefault().getRawOffset();
  String table = getTableName().toUpperCase();
  ColumnGenerator[] cols = new ColumnGenerator[] {
    HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(0),
      "date", Types.DATE, HCatFieldSchema.Type.BIGINT, 0, 0, 0 - offset,
      new Date(70, 0, 1), KeyType.NOT_A_KEY),
    HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(1),
      "time", Types.TIME, HCatFieldSchema.Type.BIGINT, 0, 0,
      36672000L - offset, new Time(10, 11, 12), KeyType.NOT_A_KEY),
    HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(2),
      "timestamp", Types.TIMESTAMP, HCatFieldSchema.Type.BIGINT, 0, 0,
      36672000L - offset, new Timestamp(70, 0, 1, 10, 11, 12, 0),
      KeyType.NOT_A_KEY),
  };
  List<String> addlArgsArray = new ArrayList<String>();
  addlArgsArray.add("--map-column-hive");
  addlArgsArray.add("COL0=bigint,COL1=bigint,COL2=bigint");
  runHCatExport(addlArgsArray, TOTAL_RECORDS, table, cols);
}
 
Example 4
Project: Homework   File: DAOEx03.java   Source Code and License 6 votes vote down vote up
@Test
public void testLogin()
{  
    Pet Pet = new Pet(11, 9527, "肥仔", 1, 60, 40, new Date(2017-1-1), "宝贝");

    Scanner sc = new Scanner(System.in);
    System.out.println("请输入登陆名:");
    String username = sc.next();
    System.out.println("请输入密码:");
    String password = sc.next();
    Master master = new Master(username, password);

    Connection conn = DBHelper.getInstance().getConnection();
    MasterDao dao = new MasterServiceImpl(conn);
    MasterService service = new MasterServiceImpl(dao);

    service.login(master);

    DBHelper.closeConnection(conn);    
}
 
Example 5
Project: taskana   File: TaskMonitorServiceImplTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testGetTaskCountByWorkbasketAndDaysInPastAndState() {
    final long daysInPast = 10L;
    List<TaskState> taskStates = Arrays.asList(TaskState.CLAIMED, TaskState.COMPLETED);
    List<DueWorkbasketCounter> expectedResult = new ArrayList<>();
    doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountByWorkbasketIdAndDaysInPastAndState(
        any(Date.class),
        any());

    List<DueWorkbasketCounter> actualResult = cut.getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast,
        taskStates);

    verify(taskanaEngineImpl, times(1)).openConnection();
    verify(taskMonitorMapperMock, times(1)).getTaskCountByWorkbasketIdAndDaysInPastAndState(any(Date.class), any());
    verify(taskanaEngineImpl, times(1)).returnConnection();
    verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
        taskMonitorMapperMock, objectReferenceMapperMock, workbasketServiceMock);
    assertThat(actualResult, equalTo(expectedResult));
}
 
Example 6
Project: QDrill   File: HiveTestDataGenerator.java   Source Code and License 6 votes vote down vote up
private String generateTestDataFileForPartitionInput() throws Exception {
  final File file = getTempFile();

  PrintWriter printWriter = new PrintWriter(file);

  String partValues[] = {"1", "2", "null"};

  for(int c = 0; c < partValues.length; c++) {
    for(int d = 0; d < partValues.length; d++) {
      for(int e = 0; e < partValues.length; e++) {
        for (int i = 1; i <= 5; i++) {
          Date date = new Date(System.currentTimeMillis());
          Timestamp ts = new Timestamp(System.currentTimeMillis());
          printWriter.printf("%s,%s,%s,%s,%s",
              date.toString(), ts.toString(), partValues[c], partValues[d], partValues[e]);
          printWriter.println();
        }
      }
    }
  }

  printWriter.close();

  return file.getPath();
}
 
Example 7
Project: JAVA-   File: TypeParseUtil.java   Source Code and License 6 votes vote down vote up
private static Object date2Obj(Object value, String type, String format) {
	String fromType = "Date";
	java.util.Date dte = (java.util.Date) value;
	if ("String".equalsIgnoreCase(type) || DataType.STRING.equalsIgnoreCase(type)) {
		if (format == null || format.length() == 0) {
			return dte.toString();
		} else {
			SimpleDateFormat sdf = new SimpleDateFormat(format);
			return sdf.format(dte);
		}
	} else if ("Date".equalsIgnoreCase(type) || DataType.DATE.equalsIgnoreCase(type)) {
		return value;
	} else if ("java.sql.Date".equalsIgnoreCase(type)) {
		return new Date(dte.getTime());
	} else if ("Time".equalsIgnoreCase(type) || DataType.TIME.equalsIgnoreCase(type)) {
		return new Time(dte.getTime());
	} else if ("Timestamp".equalsIgnoreCase(type) || DataType.TIMESTAMP.equalsIgnoreCase(type)) {
		return new Timestamp(dte.getTime());
	} else {
		throw new DataParseException(String.format(support, fromType, type));
	}
}
 
Example 8
Project: citizensLoader2b   File: AplicationTest.java   Source Code and License 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Test
public void testCrearPassword() {
	List<Ciudadano> ciudadanos = new ArrayList<Ciudadano>();

	Ciudadano ciudadano = new Ciudadano("Hugo", "Perez", "[email protected]", "Calle no se que Oviedo", "español", "1234A",
			new Date(18, 7, 1995));

	ciudadanos.add(ciudadano);
	BBDD.insertarCiudadano(ciudadanos);
	Ciudadano cBBDD = BBDD.obtenerCiudadano("1234A");
	cBBDD.crearPassword();
	String password = cBBDD.getPassword();
	BBDD.guardaarPasswordUsuario("1234A", password);
	cBBDD = BBDD.obtenerCiudadano("1234A");

	assertEquals(password, cBBDD.getPassword());
}
 
Example 9
Project: ramus   File: JDBCTemplate.java   Source Code and License 6 votes vote down vote up
public void setParam(PreparedStatement ps, int parameterIndex,
                     Object object) throws SQLException {
    if (object instanceof Timestamp) {
        ps.setTimestamp(parameterIndex, (Timestamp) object);
    } else if (object instanceof Date) {
        ps.setDate(parameterIndex, (Date) object);
    } else if (object instanceof String) {
        ps.setString(parameterIndex, (String) object);
    } else if (object instanceof Integer) {
        ps.setInt(parameterIndex, ((Integer) object).intValue());
    } else if (object instanceof Long) {
        ps.setLong(parameterIndex, ((Long) object).longValue());
    } else if (object instanceof Boolean) {
        ps.setBoolean(parameterIndex, ((Boolean) object).booleanValue());
    } else {
        ps.setObject(parameterIndex, object);
    }
}
 
Example 10
Project: BibliotecaPS   File: CallableStatementWrapper.java   Source Code and License 5 votes vote down vote up
public void setDate(String parameterName, Date x) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((CallableStatement) this.wrappedStmt).setDate(parameterName, x);
        } else {
            throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 11
Project: parabuild-ci   File: HsqlDateTime.java   Source Code and License 5 votes vote down vote up
public static Timestamp getNormalisedTimestamp(Date d) {

        synchronized (tempCalDefault) {
            setTimeInMillis(tempCalDefault, d.getTime());
            resetToDate(tempCalDefault);

            long value = getTimeInMillis(tempCalDefault);

            return new Timestamp(value);
        }
    }
 
Example 12
Project: tangyuan2   File: SqlDateTypeHandler.java   Source Code and License 5 votes vote down vote up
@Override
public void appendLog(StringBuilder builder, Date parameter, DatabaseDialect dialect) {
	// if (DatabaseDialect.MYSQL == dialect) {
	// builder.append('\'');
	// builder.append((null != parameter) ? new SimpleDateFormat("yyyy-MM-dd").format(parameter) : null);
	// builder.append('\'');
	// }
	builder.append('\'');
	builder.append((null != parameter) ? new SimpleDateFormat("yyyy-MM-dd").format(parameter) : null);
	builder.append('\'');
}
 
Example 13
Project: OpenVertretung   File: CallableStatementWrapper.java   Source Code and License 5 votes vote down vote up
public void setDate(String parameterName, Date x, Calendar cal) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((CallableStatement) this.wrappedStmt).setDate(parameterName, x, cal);
        } else {
            throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 14
Project: monarch   File: MPredicateHelperTest.java   Source Code and License 5 votes vote down vote up
/**
 * Test for Date values.
 *
 * @param constant the constant value to be tested
 * @param op the operation to be used for testing/condition against constant value
 * @param arg1 the value to be compared against the constant value
 * @param check boolean indicating the result of predicate test for above
 */
@Test(dataProvider = "getDateData")
public void testGetPredicateForDate(final Object constant, final TypePredicateOp op,
    final Date arg1, boolean check) {
  System.out.printf("PredicateHelperTest.testGetPredicateForDate :: %s -- %s -- %s -- %s\n",
      constant, op, arg1, check);

  assertUsingSerDeForType(BasicTypes.DATE, constant, op, arg1, check);
}
 
Example 15
Project: parabuild-ci   File: HsqlDateTime.java   Source Code and License 5 votes vote down vote up
public static Date getNormalisedDate(Date d) {

        synchronized (tempCalDefault) {
            setTimeInMillis(tempCalDefault, d.getTime());
            resetToDate(tempCalDefault);

            long value = getTimeInMillis(tempCalDefault);

            return new Date(value);
        }
    }
 
Example 16
Project: parabuild-ci   File: HsqlDateTime.java   Source Code and License 5 votes vote down vote up
public static String getDateString(java.util.Date x, Calendar cal) {

        synchronized (sdfd) {
            sdfd.setCalendar(cal == null ? tempCalDefault
                                         : cal);

            return sdfd.format(x);
        }
    }
 
Example 17
Project: JYLAND   File: JYComment.java   Source Code and License 5 votes vote down vote up
public JYComment(int seq, String id, String content, int boardseq, Date wdate, int likecount, int hatecount,
		String ip, int seqReply, int ref, int delflag) {
	super();
	this.seq = seq;
	this.id = id;
	this.content = content;
	this.boardseq = boardseq;
	this.wdate = wdate;
	this.likecount = likecount;
	this.hatecount = hatecount;
	this.ip = ip;
	this.seqReply = seqReply;
	this.ref = ref;
	this.delflag = delflag;
}
 
Example 18
Project: OpenVertretung   File: StatementRegressionTest.java   Source Code and License 5 votes vote down vote up
/**
 * Tests that binary dates/times are encoded/decoded correctly.
 * 
 * @throws Exception
 *             if the test fails.
 * 
 * @deprecated because we need to use this particular constructor for the
 *             date class, as Calendar-constructed dates don't pass the
 *             .equals() test :(
 */
@Deprecated
public void testServerPrepStmtAndDate() throws Exception {
    createTable("testServerPrepStmtAndDate",
            "(`P_ID` int(10) NOT NULL default '0', `R_Date` date default NULL, UNIQUE KEY `P_ID` (`P_ID`), KEY `R_Date` (`R_Date`))");
    Date dt = new java.sql.Date(102, 1, 2); // Note, this represents the date 2002-02-02

    PreparedStatement pStmt2 = this.conn.prepareStatement("INSERT INTO testServerPrepStmtAndDate (P_ID, R_Date) VALUES (171576, ?)");
    pStmt2.setDate(1, dt);
    pStmt2.executeUpdate();
    pStmt2.close();

    this.rs = this.stmt.executeQuery("SELECT R_Date FROM testServerPrepStmtAndDate");
    this.rs.next();

    System.out.println("Date that was stored (as String) " + this.rs.getString(1)); // comes back as 2002-02-02

    PreparedStatement pStmt = this.conn.prepareStatement("Select P_ID,R_Date from testServerPrepStmtAndDate Where R_Date = ?   and P_ID = 171576");
    pStmt.setDate(1, dt);

    this.rs = pStmt.executeQuery();

    assertTrue(this.rs.next());

    assertEquals("171576", this.rs.getString(1));

    assertEquals(dt, this.rs.getDate(2));
}
 
Example 19
Project: dev-courses   File: JDBCCallableStatement.java   Source Code and License 5 votes vote down vote up
/**
 * Internal value converter. Similar to its counterpart in JDBCResultSet <p>
 *
 * All trivially successful getXXX methods eventually go through this
 * method, converting if necessary from the source type to the
 * requested type.  <p>
 *
 * Conversion to the JDBC representation, if different, is handled by the
 * calling methods.
 *
 * @param columnIndex of the column value for which to perform the
 *                 conversion
 * @param targetType the org.hsqldb.types.Type object for targetType
 * @return an Object of the requested targetType, representing the value of the
 *       specified column
 * @throws SQLException when there is no rowData, the column index is
 *    invalid, or the conversion cannot be performed
 */
private Object getColumnInType(int columnIndex,
                               Type targetType) throws SQLException {

    checkGetParameterIndex(columnIndex);

    Type   sourceType;
    Object value;

    sourceType = parameterTypes[--columnIndex];
    value      = parameterValues[columnIndex];

    if (trackNull(value)) {
        return null;
    }

    if (sourceType.typeCode != targetType.typeCode) {
        try {
            value = targetType.convertToTypeJDBC(session, value,
                    sourceType);
        } catch (HsqlException e) {
            String stringValue =
                (value instanceof Number || value instanceof String
                 || value instanceof java.util.Date) ? value.toString()
                    : "instance of " + value.getClass().getName();
            String msg = "from SQL type " + sourceType.getNameString()
                         + " to " + targetType.getJDBCClassName()
                         + ", value: " + stringValue;
            HsqlException err = Error.error(ErrorCode.X_42561, msg);

            throw JDBCUtil.sqlException(err, e);
        }
    }

    return value;
}
 
Example 20
Project: atlas   File: PatchFileBuilder.java   Source Code and License 5 votes vote down vote up
/**
 *
 * @return
 */
private Manifest createManifest() {
    Manifest manifest = new Manifest();
    Attributes main = manifest.getMainAttributes();
    main.putValue("Manifest-Version", "1.0");
    main.putValue("Created-By", "1.0 (JarPatch)");
    main.putValue("Created-Time", new Date(System.currentTimeMillis()).toGMTString());
    return manifest;
}
 
Example 21
Project: BibliotecaPS   File: TimeUtil.java   Source Code and License 5 votes vote down vote up
final static Time fastTimeCreate(Calendar cal, int hour, int minute, int second, ExceptionInterceptor exceptionInterceptor) throws SQLException {
    if (hour < 0 || hour > 24) {
        throw SQLError.createSQLException(
                "Illegal hour value '" + hour + "' for java.sql.Time type in value '" + timeFormattedString(hour, minute, second) + ".",
                SQLError.SQL_STATE_ILLEGAL_ARGUMENT, exceptionInterceptor);
    }

    if (minute < 0 || minute > 59) {
        throw SQLError.createSQLException(
                "Illegal minute value '" + minute + "' for java.sql.Time type in value '" + timeFormattedString(hour, minute, second) + ".",
                SQLError.SQL_STATE_ILLEGAL_ARGUMENT, exceptionInterceptor);
    }

    if (second < 0 || second > 59) {
        throw SQLError.createSQLException(
                "Illegal minute value '" + second + "' for java.sql.Time type in value '" + timeFormattedString(hour, minute, second) + ".",
                SQLError.SQL_STATE_ILLEGAL_ARGUMENT, exceptionInterceptor);
    }

    synchronized (cal) {
        java.util.Date origCalDate = cal.getTime();
        try {
            cal.clear();

            // Set 'date' to epoch of Jan 1, 1970
            cal.set(1970, 0, 1, hour, minute, second);

            long timeAsMillis = cal.getTimeInMillis();

            return new Time(timeAsMillis);
        } finally {
            cal.setTime(origCalDate);
        }
    }
}
 
Example 22
Project: parabuild-ci   File: SSTestBugzilla216DatabaseConnector.java   Source Code and License 5 votes vote down vote up
/**
 *
 */
public void test_requestBugsFromBugzillaCanHandleEmptyProductVersion() throws Exception {
  final Date fromDate = stringToDate("2003-02-21 21:03:14");
  final Date toDate = stringToDate("2003-05-15 23:07:06");
  // empty string as a version
  Collection result = bugzillaDatabaseConnector.
    requestBugsFromBugzilla(TEST_PRODUCT_NAME, "", fromDate, toDate);
  assertEquals(7, result.size());
  assertEquals("Number of errors", 0, em.errorCount());
  // null string as a version
  result = bugzillaDatabaseConnector.
    requestBugsFromBugzilla(TEST_PRODUCT_NAME, null, fromDate, toDate);
  assertEquals(7, result.size());
  assertEquals("Number of errors", 0, em.errorCount());
}
 
Example 23
Project: participants_i2a   File: Application.java   Source Code and License 5 votes vote down vote up
@Bean
public CommandLineRunner demo(ParticipantRepository repository){

    return (args) -> {
        Participant pepe = new Participant("pepe", "pepe", "[email protected]", new Date(123),
                "pepe", "pepe", "pepe", "pepe");
        repository.save(pepe);
        Participant participant = repository.findParticipantByEmailAndPassword
                ("[email protected]", "pepe");
        log.info(participant.toString());

    };
}
 
Example 24
Project: BibliotecaPS   File: ResultSetRegressionTest.java   Source Code and License 5 votes vote down vote up
/**
 * @deprecated because we use deprecated methods
 */
@Deprecated
public void testBug34913() throws Exception {
    Timestamp ts = new Timestamp(new Date(109, 5, 1).getTime());

    this.pstmt = ((com.mysql.jdbc.Connection) this.conn).serverPrepareStatement("SELECT 'abcdefghij', ?");
    this.pstmt.setTimestamp(1, ts);
    this.rs = this.pstmt.executeQuery();
    this.rs.next();
    assertTrue(this.rs.getTimestamp(2).getMonth() == 5);
    assertTrue(this.rs.getTimestamp(2).getDate() == 1);
}
 
Example 25
Project: jooq-flyway-typesafe-migration   File: v3_AuthorRecord.java   Source Code and License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public v3_AuthorRecord values(Integer value1, String value2, String value3, Date value4, Integer value5, String value6, Integer value7) {
    value1(value1);
    value2(value2);
    value3(value3);
    value4(value4);
    value5(value5);
    value6(value6);
    value7(value7);
    return this;
}
 
Example 26
Project: ServiceServer   File: MovieOnShowController.java   Source Code and License 5 votes vote down vote up
@RequestMapping(path = "/day",
                method = RequestMethod.GET,
                produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public RestResponse getMovieOnShowByDay(
    @RequestParam("movieId") Integer movieId,
    @RequestParam("cinemaId") Integer cinemaId,
    @RequestParam("showDate") Date showDate,
    HttpServletRequest request, HttpServletResponse response) {
    LogUtil.logReq(Log, request);
    List<Integer> idsList = movieOnShowService.getMovieOnShowByDate(movieId, showDate, cinemaId);
    return new CollectionResponse(idsList);
}
 
Example 27
Project: tcp   File: AccionHasProducto.java   Source Code and License 4 votes vote down vote up
public Date getFechaInsercion() {
	return fechaInsercion;
}
 
Example 28
Project: spr   File: Version.java   Source Code and License 4 votes vote down vote up
public Date getFechaActualizacion() {
	return fechaActualizacion;
}
 
Example 29
Project: tcp   File: Evidencia.java   Source Code and License 4 votes vote down vote up
public Date getFechaInsercion() {
	return fechaInsercion;
}
 
Example 30
Project: tcp   File: Hito.java   Source Code and License 4 votes vote down vote up
public Date getFechaInsercion() {
	return fechaInsercion;
}
 
Example 31
Project: tcp   File: Periodo.java   Source Code and License 4 votes vote down vote up
public Date getFechaInsercion() {
	return fechaInsercion;
}
 
Example 32
Project: DataM   File: DataHandle.java   Source Code and License 4 votes vote down vote up
public void resolveTable(Map<String, Object> message) {
    if (message == null || message.isEmpty() || message.get(key) == null)
        return;
    DefaultFormattingConversionService cs = new DefaultFormattingConversionService(true);
    message.put(key, cs.convert(message.get(key), Long.class));
    logger.info("start to resolve message");
    String[] baseTableColumn = tDataBase.split(",");
    String[] extraTableColumn = tDataExtra.split(",");
    String[] customTableColumn = tDataCustom.split(",");
    Map<String, Object> baseTable = new HashMap<>();
    Map<String, Object> extraTable = new HashMap<>();
    Map<String, Object> customTable = new HashMap<>();
    long uuid = CustomUUID.get().nextId();
    baseTable.put(index, uuid);
    extraTable.put(index, uuid);

    baseTable.put(attr, new Date((long) message.get(key)));
    extraTable.put(attr, new Date((long) message.get(key)));

    Arrays.asList(baseTableColumn).stream().forEach(e -> {
        baseTable.put(e, message.get(e));
    });
    Arrays.asList(extraTableColumn).stream().forEach(e -> {
        extraTable.put(e, message.get(e));
    });
    Arrays.asList(customTableColumn).stream().forEach(e -> {
        if (message.get(e) == null || "".equals(((String) message.get(e)).trim())) {
            return;
        }
        customTable.put(e, message.get(e));
    });
    logger.info("start to insert DB");
    baseDataReportMapper.insertReportData(baseTable);
    extraDataReportMapper.insertReportData(extraTable);
    if (customTable.size() > 0) {
        customTable.put(index, uuid);
        customTable.put(attr, new Date((long) message.get(key)));
        Arrays.asList(customTableColumn).stream().forEach(e -> {
            if (customTable.get(e) == null || "".equals(((String) customTable.get(e)).trim()))
                customTable.put(e, Constants.TABLE_COLUMN_TYPE.get(e));
        });
        customDataReportMapper.insertReportData(customTable);
    }
    logger.info("message insert DB successed");
}
 
Example 33
Project: tcp   File: Cronograma.java   Source Code and License 4 votes vote down vote up
public void setFechaActualizacion(Date fechaActualizacion) {
	this.fechaActualizacion = fechaActualizacion;
}
 
Example 34
Project: Earthquake-App   File: EarthquakeAdapter.java   Source Code and License 4 votes vote down vote up
public String formatDate(Date dateObject) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("LLL dd, yyyy");
    String carl = dateFormat.format(dateObject);
    return carl;
}
 
Example 35
Project: openjdk-jdk10   File: DateTests.java   Source Code and License 4 votes vote down vote up
@Test
public void test11() {
    Date d = Date.valueOf("1961-08-30");
    Date d2 = new Date(System.currentTimeMillis());
    assertTrue(d.compareTo(d2) == -1, "Error d.compareTo(d2) != -1");
}
 
Example 36
Project: tomcat7   File: Statement.java   Source Code and License 4 votes vote down vote up
@Override
public Date getDate(int parameterIndex, Calendar cal) throws SQLException {
    // TODO Auto-generated method stub
    return null;
}
 
Example 37
Project: jdk8u-jdk   File: DateTests.java   Source Code and License 4 votes vote down vote up
@Test(expectedExceptions = NullPointerException.class)
public void test15() throws Exception {
    LocalDate ld = null;
    Date.valueOf(ld);
}
 
Example 38
Project: org.ops4j.pax.transx   File: PreparedStatementWrapper.java   Source Code and License 4 votes vote down vote up
public void setDate(int parameterIndex, Date x) throws SQLException {
	ps.setDate(parameterIndex, x);
}
 
Example 39
Project: Homework   File: JDBCEx05.java   Source Code and License 4 votes vote down vote up
public Date getHiredate()
{
	return this.hiredate;
}
 
Example 40
Project: blanco-sfdc-jdbc-driver   File: AbstractBlancoGenericJdbcPreparedStatement.java   Source Code and License 4 votes vote down vote up
public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
	throw new SQLException("Not Implemented: setDate(int parameterIndex, Date x, Calendar cal)");
}
 
Example 41
Project: jdk8u-jdk   File: StubJdbcRowSetImpl.java   Source Code and License 4 votes vote down vote up
@Override
public Date getDate(String columnLabel, Calendar cal) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
Example 42
Project: QDrill   File: Drill2489CallsAfterCloseThrowExceptionsTest.java   Source Code and License 4 votes vote down vote up
@Test( expected = AlreadyClosedSqlException.class )
public void testClosedResultSet_updateDate2_throws() throws SQLException {
  closedResultSet.updateDate( "columnLabel", (Date) null );
}
 
Example 43
Project: L2J-Global   File: L2PcInstance.java   Source Code and License 4 votes vote down vote up
/**
 * Create a new player in the characters table of the database.
 * @return
 */
private boolean createDb()
{
	try (Connection con = DatabaseFactory.getInstance().getConnection();
		PreparedStatement statement = con.prepareStatement(INSERT_CHARACTER))
	{
		statement.setString(1, _accountName);
		statement.setInt(2, getObjectId());
		statement.setString(3, getName());
		statement.setInt(4, getLevel());
		statement.setInt(5, getMaxHp());
		statement.setDouble(6, getCurrentHp());
		statement.setInt(7, getMaxCp());
		statement.setDouble(8, getCurrentCp());
		statement.setInt(9, getMaxMp());
		statement.setDouble(10, getCurrentMp());
		statement.setInt(11, getAppearance().getFace());
		statement.setInt(12, getAppearance().getHairStyle());
		statement.setInt(13, getAppearance().getHairColor());
		statement.setInt(14, getAppearance().getSex() ? 1 : 0);
		statement.setLong(15, getExp());
		statement.setLong(16, getSp());
		statement.setInt(17, getReputation());
		statement.setInt(18, getFame());
		statement.setInt(19, getRaidbossPoints());
		statement.setInt(20, getPvpKills());
		statement.setInt(21, getPkKills());
		statement.setInt(22, getClanId());
		statement.setInt(23, getRace().ordinal());
		statement.setInt(24, getClassId().getId());
		statement.setLong(25, getDeleteTimer());
		statement.setInt(26, hasDwarvenCraft() ? 1 : 0);
		statement.setString(27, getTitle());
		statement.setInt(28, getAppearance().getTitleColor());
		statement.setInt(29, isOnlineInt());
		statement.setInt(30, getClanPrivileges().getBitmask());
		statement.setInt(31, getWantsPeace());
		statement.setInt(32, getBaseClass());
		statement.setInt(33, isNoble() ? 1 : 0);
		statement.setLong(34, 0);
		statement.setInt(35, PcStat.MIN_VITALITY_POINTS);
		statement.setDate(36, new Date(getCreateDate().getTimeInMillis()));
		statement.executeUpdate();
	}
	catch (Exception e)
	{
		_log.log(Level.SEVERE, "Could not insert char data: " + e.getMessage(), e);
		return false;
	}
	return true;
}
 
Example 44
Project: tcp   File: Evidencia.java   Source Code and License 4 votes vote down vote up
public Date getFechaActualizacion() {
	return fechaActualizacion;
}
 
Example 45
Project: tcp   File: UnidadMedida.java   Source Code and License 4 votes vote down vote up
public Date getFechaActualizacion() {
	return fechaActualizacion;
}
 
Example 46
Project: jdk8u-jdk   File: DateTests.java   Source Code and License 4 votes vote down vote up
@Test(expectedExceptions = IllegalArgumentException.class)
public void test21() throws Exception {
    Date d = Date.valueOf("1961-08-30");
    d.getHours();
}
 
Example 47
Project: tcp   File: FactHitos.java   Source Code and License 4 votes vote down vote up
public Date getAccion_fecha_entrega() {
	return accion_fecha_entrega;
}
 
Example 48
Project: BibliotecaPS   File: TimeUtil.java   Source Code and License 4 votes vote down vote up
final static Timestamp fastTimestampCreate(boolean useGmtConversion, Calendar gmtCalIfNeeded, Calendar cal, int year, int month, int day, int hour,
        int minute, int seconds, int secondsPart) {

    synchronized (cal) {
        java.util.Date origCalDate = cal.getTime();
        try {
            cal.clear();

            // why-oh-why is this different than java.util.date, in the year part, but it still keeps the silly '0' for the start month????
            cal.set(year, month - 1, day, hour, minute, seconds);

            int offsetDiff = 0;

            if (useGmtConversion) {
                int fromOffset = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET);

                if (gmtCalIfNeeded == null) {
                    gmtCalIfNeeded = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
                }
                gmtCalIfNeeded.clear();

                gmtCalIfNeeded.setTimeInMillis(cal.getTimeInMillis());

                int toOffset = gmtCalIfNeeded.get(Calendar.ZONE_OFFSET) + gmtCalIfNeeded.get(Calendar.DST_OFFSET);
                offsetDiff = fromOffset - toOffset;
            }

            if (secondsPart != 0) {
                cal.set(Calendar.MILLISECOND, secondsPart / 1000000);
            }

            long tsAsMillis = cal.getTimeInMillis();

            Timestamp ts = new Timestamp(tsAsMillis + offsetDiff);

            ts.setNanos(secondsPart);

            return ts;
        } finally {
            cal.setTime(origCalDate);
        }
    }
}
 
Example 49
Project: nixmash-blog   File: GitHubStats.java   Source Code and License 4 votes vote down vote up
@Basic
@Column(name = "stat_date", nullable = false)
public Date getStatDate() {
    return statDate;
}
 
Example 50
Project: sstore-soft   File: JDBC4ResultSet.java   Source Code and License 4 votes vote down vote up
@Override
public Date getDate(String columnLabel) throws SQLException {
    return getDate(findColumn(columnLabel));
}
 
Example 51
Project: dswork.jdbc   File: CallableStatementSpy.java   Source Code and License 4 votes vote down vote up
public void setDate(String parameterName, Date x) throws SQLException
{
	realCallableStatement.setDate(parameterName, x);
}
 
Example 52
Project: Agent-Benchmarks   File: SimulateResultSet.java   Source Code and License 4 votes vote down vote up
@Override public Date getDate(String columnLabel) throws SQLException {
    return null;
}
 
Example 53
Project: Homework   File: DAOEx02.java   Source Code and License 4 votes vote down vote up
public boolean adoptPet()
{
    LOGGER.info("----欢迎光临宠物乐园----");
    LOGGER.info("请输入登陆名:");
    String username = sc.next();
    LOGGER.info("请输入密码:");
    String password = sc.next();
    Master master = new Master(username, password);
    if (!login(master)) 
    {
        return false;
    }

    LOGGER.info("请选择宠物类型:");
    PetTypeDao petTypeDao = new PetTypeDaoImpl();
    List<String> petTypes = petTypeDao.findAllPetType();

    StringBuffer sb = new StringBuffer();
    for (String element: petTypes) 
    {
        sb.append(element).append(" | ");
    }

    LOGGER.info(sb);

    String select = sc.next();
    int petTypeId = petTypeDao.findPetTypeId(select);
    if (petTypeId == 0) 
    {
        LOGGER.info("宠物类型输入有误,领养失败!");
        return false;
    }

    LOGGER.info("您选择的宠物类型编号是{}", petTypeId);
    LOGGER.info("请输入宠物昵称:");
    String name = sc.next();
    Pet pet = new Pet(1, username, name, new PetType(petTypeId, select), 60, 0, new Date(System.currentTimeMillis()), "良好");
    PetDao petDao = new PetDaoImpl();
    if (petDao.save(pet) == 1) 
    {
        petDao.closeConnection();
        return true;
    }
    petDao.closeConnection();
    return false;
}
 
Example 54
Project: Spring-5.0-Cookbook   File: Employee.java   Source Code and License 4 votes vote down vote up
public void setBirthday(Date birthday) {
	this.birthday = birthday;
}
 
Example 55
Project: parabuild-ci   File: ResultSetWrapper.java   Source Code and License 4 votes vote down vote up
public Date getDate(String columnName) throws SQLException {
	return rs.getDate( findColumn(columnName) );
}
 
Example 56
Project: Spring-5.0-Cookbook   File: EmployeeForm.java   Source Code and License 4 votes vote down vote up
public Date getBirthday() {
	return birthday;
}
 
Example 57
Project: tcp   File: UnidadMedida.java   Source Code and License 4 votes vote down vote up
public void setFechaInsercion(Date fechaInsercion) {
	this.fechaInsercion = fechaInsercion;
}
 
Example 58
Project: apache-tomcat-7.0.73-with-comment   File: Statement.java   Source Code and License 4 votes vote down vote up
@Override
public Date getDate(String parameterName, Calendar cal) throws SQLException {
    // TODO Auto-generated method stub
    return null;
}
 
Example 59
Project: the-vigilantes   File: DateTest.java   Source Code and License 4 votes vote down vote up
public void testTimestamp() throws SQLException {
    createTable("DATETEST", "(tstamp TIMESTAMP, dt DATE, dtime DATETIME, tm TIME)");

    this.pstmt = this.conn.prepareStatement("INSERT INTO DATETEST(tstamp, dt, dtime, tm) VALUES (?, ?, ?, ?)");

    // TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.MONTH, 6);
    cal.set(Calendar.DAY_OF_MONTH, 3);
    cal.set(Calendar.YEAR, 2002);
    cal.set(Calendar.HOUR, 7);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.AM_PM, Calendar.AM);
    cal.getTime();
    System.out.println(cal);

    // DateFormat df = SimpleDateFormat.getInstance();
    DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss z");

    Calendar calGMT = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    // df.setTimeZone(TimeZone.getTimeZone("GMT"));
    Timestamp nowTstamp = new Timestamp(cal.getTime().getTime());
    java.sql.Date nowDate = new java.sql.Date(cal.getTime().getTime());
    Timestamp nowDatetime = new Timestamp(cal.getTime().getTime());
    java.sql.Time nowTime = new java.sql.Time(cal.getTime().getTime());
    System.out.println("** Times with given calendar (before storing) **\n");
    System.out.println("TIMESTAMP:\t" + nowTstamp.getTime() + " -> " + df.format(nowTstamp));
    System.out.println("DATE:\t\t" + nowDate.getTime() + " -> " + df.format(nowDate));
    System.out.println("DATETIME:\t" + nowDatetime.getTime() + " -> " + df.format(nowDatetime));
    System.out.println("DATE:\t\t" + nowDate.getTime() + " -> " + df.format(nowDate));
    System.out.println("TIME:\t\t" + nowTime.getTime() + " -> " + df.format(nowTime));
    System.out.println("\n");
    this.pstmt.setTimestamp(1, nowTstamp, calGMT);
    // have to use the same TimeZone as used to create or there will be
    // shift
    this.pstmt.setDate(2, nowDate, cal);
    this.pstmt.setTimestamp(3, nowDatetime, calGMT);
    // have to use the same TimeZone as used to create or there will be
    // shift
    this.pstmt.setTime(4, nowTime, cal);
    this.pstmt.execute();

    this.pstmt.getUpdateCount();
    this.pstmt.clearParameters();
    this.rs = this.stmt.executeQuery("SELECT * from DATETEST");

    java.sql.Date thenDate = null;

    while (this.rs.next()) {
        Timestamp thenTstamp = this.rs.getTimestamp(1, calGMT);
        thenDate = this.rs.getDate(2, cal);

        java.sql.Timestamp thenDatetime = this.rs.getTimestamp(3, calGMT);

        java.sql.Time thenTime = this.rs.getTime(4, cal);
        System.out.println("** Times with given calendar (retrieved from database) **\n");
        System.out.println("TIMESTAMP:\t" + thenTstamp.getTime() + " -> " + df.format(thenTstamp));
        System.out.println("DATE:\t\t" + thenDate.getTime() + " -> " + df.format(thenDate));
        System.out.println("DATETIME:\t" + thenDatetime.getTime() + " -> " + df.format(thenDatetime));
        System.out.println("TIME:\t\t" + thenTime.getTime() + " -> " + df.format(thenTime));
        System.out.println("\n");
    }

    this.rs.close();
    this.rs = null;
}
 
Example 60
Project: tomcat7   File: Statement.java   Source Code and License 4 votes vote down vote up
@Override
public Date getDate(String parameterName, Calendar cal) throws SQLException {
    // TODO Auto-generated method stub
    return null;
}