APISonar


java.sql.Types.DATE

> java > sql > Types > DATE
java APIs sql APIs Types APIs DATE APIs

Example 1
public void setDate(int parameterIndex, Date x)
            throws SQLException
    {
        checkOpen();
        if (x == null) {
            setNull(parameterIndex, Types.DATE);
        }
        else {
            setParameter(parameterIndex, formatLiteral("DATE", DATE_FORMATTER.print(x.getTime())));
        }
    }
Example 2
public void testSetParameterValueWithDateAndUtilDate() throws SQLException {
		java.util.Date date = new java.util.Date(1000);
		StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.DATE, null, date);
		verify(preparedStatement).setDate(1, new java.sql.Date(1000));
	}
Example 3
public java.sql.Date getDate(int i, java.util.Calendar cal) throws SQLException {
    checkClosed();
    checkIndex(i, Types.DATE, "Date");

    if (callResult[i - 1] == null) {
      return null;
    }

    String value = callResult[i - 1].toString();
    return connection.getTimestampUtils().toDate(cal, value);
  }
Example 4
public void testSetLocalDateWithType() throws SQLException {
    LocalDate data = LocalDate.parse("1971-12-15");
    java.sql.Date actual = insertThenReadWithType(data, Types.DATE, "date_column", java.sql.Date.class);
    java.sql.Date expected = java.sql.Date.valueOf("1971-12-15");
    assertEquals(expected, actual);
  }
Example 5
@Test public void testDate() {
    SqlTypeName tn =
        SqlTypeName.getNameForJdbcType(Types.DATE);
    assertEquals(
        "DATE did not map to DATE",
        SqlTypeName.DATE,
        tn);
  }
Example 6
public void readOfDateFieldWithDateColumnWritesDate() throws Exception {
    FieldType fieldType = FieldType.DATE;
    when(metaData.getColumnType(1)).thenReturn(Types.DATE);
    java.sql.Date sqlDate = java.sql.Date.valueOf("1979-09-11");
    Date expectedValue = new Date(sqlDate.getTime());
    when(resultSet.getDate(1)).thenReturn(sqlDate);
    sqlToPdxInstance.addMapping(COLUMN_NAME_1, PDX_FIELD_NAME_1, fieldType);

    PdxInstance result = createPdxInstance();

    verifyResult(expectedValue, result);
  }
Example 7
public void setValue(java.sql.Date field) throws SQLException {
        if (field != null) {
            _ps.setDate(_ind, field);
        } else {
            _ps.setNull(_ind, Types.DATE);
        }
        _ind++;
    }
Example 8
public DateColumn(String label, int nullable) throws SQLException {
        super(label, Types.DATE, nullable);
        this.setClassName(Date.class.getCanonicalName());
    }
Example 9
public void assertGetValueByDate() throws SQLException {
        ResultSet resultSet = getMockedResultSet(Types.DATE);
        when(resultSet.getDate(1)).thenReturn(new Date(0L));
        MemoryQueryResult actual = new MemoryQueryResult(resultSet);
        assertTrue(actual.next());
        assertThat(actual.getValue(1, Date.class), is((Object) new Date(0L)));
        assertFalse(actual.next());
    }
Example 10
private boolean checkCalendarParam(int pos, Calendar cal) throws SQLException {
        // 2nd param is ignored when instanceof java.util.Date
        return checkParam(pos, Types.DATE, cal);
    }
Example 11
public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
        setParameter(parameterIndex, new JdbcParameter(Types.DATE, x, cal));

        createChain().preparedStatement_setDate(this, parameterIndex, x, cal);
    }
Example 12
public static Object coerceToSQLType(int jdbcType, Object value) {
        if (value.getClass() == java.util.Date.class) {
            if (jdbcType == Types.DATE) {
                return new java.sql.Date(((java.util.Date) value).getTime());
            } else if (jdbcType == Types.TIME) {
                return new java.sql.Time(((java.util.Date) value).getTime());
            } else if (jdbcType == Types.TIMESTAMP) {
                return new java.sql.Timestamp(((java.util.Date) value).getTime());
            }
        } else if (value.getClass() == Character.class && jdbcType == Types.VARCHAR) {
            value = value.toString();
        }
        return value;
    }
Example 13
public void testSetParameterValueWithDateAndCalendar() throws SQLException {
		java.util.Calendar cal = new GregorianCalendar();
		ps.setDate(1, new java.sql.Date(cal.getTime().getTime()), cal);
		psControl.setVoidCallable(1);
		psControl.replay();
		StatementCreatorUtils.setParameterValue(ps, 1, Types.DATE, null, cal);
	}
Example 14
public static boolean isDate(int dataType) {
        List<Integer> validTypes = Arrays.asList(
                Types.DATE,
                Types.TIME,
                Types.TIMESTAMP
        );

        return validTypes.contains(dataType);
    }
Example 15
public void bind(DataBind b, T value) throws SQLException {
    if (value == null) {
      b.setNull(Types.DATE);
    } else {
      b.setDate(convertToDate(value));
    }
  }
Example 16
private static Map<Class<?>, Integer> types() {
        final Map<Class<?>, Integer> types = new HashMap<>();
        types.put(LocalDate.class, Types.DATE);
        types.put(LocalTime.class, Types.TIME);
        types.put(LocalDateTime.class, Types.TIMESTAMP);
        types.put(OffsetDateTime.class, Types.TIMESTAMP_WITH_TIMEZONE);
        return types;
    }
Example 17
public ScalarType<java.util.Date> createUtilDate(JsonConfig.DateTime jsonDateTime, JsonConfig.Date jsonDate, int utilDateType) {

    switch (utilDateType) {
      case Types.DATE:
        return new ScalarTypeUtilDate.DateType(jsonDate);

      case Types.TIMESTAMP:
        return new ScalarTypeUtilDate.TimestampType(jsonDateTime);

      default:
        throw new RuntimeException("Invalid type " + utilDateType);
    }
  }
Example 18
public String datetimeToQueryString(String datetime, int columnType) {
    if (columnType != Types.TIMESTAMP && columnType != Types.DATE) {
      String msg = "Column type is neither timestamp nor date!";
      LOG.error(msg);
      throw new RuntimeException(msg);
    }
    return "'" + datetime + "'";
  }
Example 19
private void assertDateParam(ParameterMetaData pmd, int param) throws SQLException {
    assertThat(pmd.getParameterType(param), is(equalTo(Types.DATE)));
    assertThat(pmd.getParameterTypeName(param), is(equalTo("DATE")));
    assertThat(pmd.getPrecision(param), is(equalTo(0)));
    assertThat(pmd.getScale(param), is(equalTo(0)));
    assertThat(pmd.getParameterClassName(param), is(equalTo(Date.class.getName())));
    assertThat(pmd.getParameterMode(param), is(equalTo(ParameterMetaData.parameterModeIn)));
    assertThat(pmd.isNullable(param), is(equalTo(ParameterMetaData.parameterNullableUnknown)));
    assertThat(pmd.isSigned(param), is(false));
  }
Example 20
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
        try {
            prep.setObject(parameterIndex, JSR310Utils.valueToLocalDate(this), Types.DATE);
            return;
        } catch (SQLException ignore) {
            // Nothing to do
        }
        prep.setDate(parameterIndex, getDate(null));
    }
Example 21
public void registerSqlTypeToSqlTypeNameOverrides(Map<Integer, String> overrides) {
        super.registerSqlTypeToSqlTypeNameOverrides(overrides);
        overrides.put(Types.REAL, "DOUBLE PRECISION");
        overrides.put(Types.DOUBLE, "DOUBLE PRECISION");
        overrides.put(Types.FLOAT, "FLOAT");
        // starting with Oracle 11 + recent JDBC drivers the DATE type does not have a mapping
        // anymore in the JDBC driver, manually register it instead
        overrides.put(Types.DATE, "DATE");
        // overriding default java.sql.Timestamp to Oracle DATE mapping
        overrides.put(Types.TIMESTAMP, "TIMESTAMP");
    }
Example 22
public String serialize(String literal, int jdbcType) {
        switch (jdbcType) {
            case Types.TIMESTAMP:
            case TIMESTAMP_WITH_TIMEZONE:
                return "timestamp '" + literal + "'";
            case Types.DATE:
                return "date '" + literal + "'";
            case Types.TIME:
            case TIME_WITH_TIMEZONE:
                return "timestamp '1970-01-01 " + literal + "'";
            default:
                return super.serialize(literal, jdbcType);
        }
    }
Example 23
public String datetimeToQueryString(String datetime, int columnType) {
    if (columnType == Types.TIMESTAMP) {
      return "TO_TIMESTAMP('" + datetime + "', 'YYYY-MM-DD HH24:MI:SS.FF')";
    } else if (columnType == Types.DATE) {
      // converting timestamp of the form 2012-11-11 11:11:11.00 to
      // date of the form 2011:11:11 11:11:11
      datetime = datetime.split("\\.")[0];
      return "TO_DATE('" + datetime + "', 'YYYY-MM-DD HH24:MI:SS')";
    } else {
      String msg = "Column type is neither timestamp nor date!";
      LOG.error(msg);
      throw new RuntimeException(msg);
    }
  }
Example 24
public Object getValueFromObject(DBCSession session, DBSTypedObject type, Object object, boolean copy) throws DBCException {
        Object value = super.getValueFromObject(session, type, object, copy);
        if (value instanceof Date) {
            switch (type.getTypeID()) {
                case Types.TIME:
                case Types.TIME_WITH_TIMEZONE:
                    return getTimeValue(value);
                case Types.DATE:
                    return getDateValue(value);
                default:
                    return getTimestampValue(value);
            }
        }
        return value;
    }
Example 25
protected Format getNativeValueFormat(DBSTypedObject type) {
        switch (type.getTypeID()) {
            case Types.TIMESTAMP:
                return DEFAULT_DATETIME_FORMAT;
            case Types.TIMESTAMP_WITH_TIMEZONE:
                return DEFAULT_DATETIME_FORMAT;
            case Types.TIME:
                return DEFAULT_TIME_FORMAT;
            case Types.TIME_WITH_TIMEZONE:
                return DEFAULT_TIME_FORMAT;
            case Types.DATE:
                return DEFAULT_DATE_FORMAT;
        }
        return null;
    }