java.sql.Date.toString()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(257)

本文整理了Java中java.sql.Date.toString()方法的一些代码示例,展示了Date.toString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Date.toString()方法的具体详情如下:
包路径:java.sql.Date
类名称:Date
方法名:toString

Date.toString介绍

[英]Produces a string representation of the date in SQL format
[中]以SQL格式生成日期的字符串表示形式

代码示例

代码示例来源:origin: com.h2database/h2

/**
 * Format a date to the Java source code that represents this object.
 *
 * @param x the date to convert
 * @return the Java source code
 */
protected static String quoteDate(java.sql.Date x) {
  if (x == null) {
    return "null";
  }
  return "Date.valueOf(\"" + x.toString() + "\")";
}

代码示例来源:origin: JSQLParser/JSqlParser

@Override
  public String toString() {
    return "{d '" + value.toString() + "'}";
  }
}

代码示例来源:origin: lealone/Lealone

/**
 * Format a date to the Java source code that represents this object.
 *
 * @param x the date to convert
 * @return the Java source code
 */
protected static String quoteDate(java.sql.Date x) {
  if (x == null) {
    return "null";
  }
  return "Date.valueOf(\"" + x.toString() + "\")";
}

代码示例来源:origin: apache/drill

@Override
public String vectorExpressionParameters() {
 return "col " + colNum + ", val " + value.toString();
}

代码示例来源:origin: apache/hive

public void setDate(int parameterIndex, Date x) throws SQLException {
 this.parameters.put(parameterIndex, "'" + x.toString() + "'");
}

代码示例来源:origin: hibernate/hibernate-orm

public String objectToSQLString(Date value, Dialect dialect) throws Exception {
  final java.sql.Date jdbcDate = java.sql.Date.class.isInstance( value )
      ? ( java.sql.Date ) value
      : new java.sql.Date( value.getTime() );
  // TODO : use JDBC date literal escape syntax? -> {d 'date-string'} in yyyy-mm-dd format
  return StringType.INSTANCE.objectToSQLString( jdbcDate.toString(), dialect );
}

代码示例来源:origin: org.codehaus.jackson/jackson-mapper-asl

@Override
public void serialize(java.sql.Date value, JsonGenerator jgen, SerializerProvider provider)
  throws IOException, JsonGenerationException
{
  jgen.writeString(value.toString());
}

代码示例来源:origin: apache/hive

@Override
public String toString() {
 // For toString, the time does not matter
 return get(false).toString();
}

代码示例来源:origin: apache/hive

@Override
public String vectorExpressionParameters() {
 return getColumnParamString(0, colNum) + ", val " + value.toString();
}

代码示例来源:origin: JSQLParser/JSqlParser

@Override
public void visit(DateValue dateValue) {
  buffer.append("{d '").append(dateValue.getValue().toString()).append("'}");
}

代码示例来源:origin: alibaba/mdrill

public void visit(DateValue dateValue) {
  buffer.append("{d '" + dateValue.getValue().toString() + "'}");
}
public void visit(TimestampValue timestampValue) {

代码示例来源:origin: apache/hive

@Override
 public List<MutablePair<String, String>> getIntervals(String lowerBound, String upperBound, int numPartitions, TypeInfo
     typeInfo) {
  List<MutablePair<String, String>> intervals = new ArrayList<>();
  Date dateLower = Date.valueOf(lowerBound);
  Date dateUpper = Date.valueOf(upperBound);
  double dateInterval = (dateUpper.getTime() - dateLower.getTime())/(double)numPartitions;
  Date splitDateLower, splitDateUpper;
  for (int i=0;i<numPartitions;i++) {
   splitDateLower = new Date(Math.round(dateLower.getTime() + dateInterval*i));
   splitDateUpper = new Date(Math.round(dateLower.getTime() + dateInterval*(i+1)));
   if (splitDateLower.compareTo(splitDateUpper) < 0) {
    intervals.add(new MutablePair<String, String>(splitDateLower.toString(), splitDateUpper.toString()));
   }
  }
  return intervals;
 }
}

代码示例来源:origin: robovm/robovm

public void setDate(int parameterIndex, java.sql.Date x)
throws SQLException {
if (parameterIndex < 1 || parameterIndex > args.length) {
  throw new SQLException("bad parameter index");
}
if (x == null) {
  args[parameterIndex - 1] = nullrepl ? "" : null;
} else {
  if (conn.useJulian) {
  args[parameterIndex - 1] = java.lang.Double.toString(SQLite.Database.julian_from_long(x.getTime()));
  } else {
  args[parameterIndex - 1] = x.toString();
  }
}
blobs[parameterIndex - 1] = false;
}

代码示例来源:origin: robovm/robovm

public void updateDate(int colIndex, java.sql.Date d) throws SQLException {
isUpdatable();
if (tr == null || colIndex < 1 || colIndex > tr.ncolumns) {
  throw new SQLException("column " + colIndex + " not found");
}
fillRowbuf();
rowbuf[colIndex - 1] = d.toString();
}

代码示例来源:origin: redisson/redisson

@Override
  public void serialize(java.sql.Date value, JsonGenerator g, SerializerProvider provider)
    throws IOException
  {
    if (_asTimestamp(provider)) {
      g.writeNumber(_timestamp(value));
      return;
    }
    // Alas, can't just call `_serializeAsString()`....
    if (_customFormat == null) {
      // 11-Oct-2016, tatu: For backwards-compatibility purposes, we shall just use
      //    the awful standard JDK serialization via `sqlDate.toString()`... this
      //    is problematic in multiple ways (including using arbitrary timezone...)
      g.writeString(value.toString());
      return;
    }
    _serializeAsString(value, g, provider);
  }
}

代码示例来源:origin: apache/drill

@Override
 protected void func(BytesColumnVector outV, long[] vector, int i) {
  dt.setTime(DateWritable.daysToMillis((int) vector[i]));
  byte[] temp = dt.toString().getBytes();
  assign(outV, i, temp, temp.length);
 }
}

代码示例来源:origin: prestodb/presto

@Override
  public void serialize(java.sql.Date value, JsonGenerator g, SerializerProvider provider)
    throws IOException
  {
    if (_asTimestamp(provider)) {
      g.writeNumber(_timestamp(value));
      return;
    }
    // Alas, can't just call `_serializeAsString()`....
    if (_customFormat == null) {
      // 11-Oct-2016, tatu: For backwards-compatibility purposes, we shall just use
      //    the awful standard JDK serialization via `sqlDate.toString()`... this
      //    is problematic in multiple ways (including using arbitrary timezone...)
      g.writeString(value.toString());
      return;
    }
    _serializeAsString(value, g, provider);
  }
}

代码示例来源:origin: apache/drill

@Test
public void testDateAggFunction() throws Exception{
 String query = "SELECT max(cast(HIRE_DATE as date)) as MAX_DATE, min(cast(HIRE_DATE as date)) as MIN_DATE" +
   " FROM `employee.json`";
 String t  = new Date(ISOChronology.getInstance().getDateTimeMillis(1998, 1, 1, 0)).toString();
 String t1 = new Date(ISOChronology.getInstance().getDateTimeMillis(1993, 5, 1, 0)).toString();
 String result = "MAX_DATE="+ t + "; " + "MIN_DATE=" + t1 + "\n";
 withFull("cp")
   .sql(query)
   .returns(result);
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testSimpleObject() throws Exception {
  SimplePerson p = new SimplePerson(1, "Test", java.sql.Date.valueOf("1977-01-26"), 1000.55, 39, "CIO", 25);
  jcache().put("simplePersonKey", p);
  String ret = content(DEFAULT_CACHE_NAME, GridRestCommand.CACHE_GET, "key", "simplePersonKey");
  info("Get command result: " + ret);
  JsonNode res = assertResponseSucceeded(ret, false);
  assertEquals(p.id, res.get("id").asInt());
  assertEquals(p.name, res.get("name").asText());
  assertEquals(p.birthday.toString(), res.get("birthday").asText());
  assertEquals(p.salary, res.get("salary").asDouble());
  assertNull(res.get("age"));
  assertEquals(p.post, res.get("post").asText());
  assertEquals(25, res.get("bonus").asInt());
}

代码示例来源:origin: apache/nifi

@Test
public void testConvertToAvroStreamForDateTimeAsString() throws SQLException, IOException, ParseException {
  final JdbcCommon.AvroConversionOptions options = JdbcCommon.AvroConversionOptions
      .builder().convertNames(true).useLogicalTypes(false).build();
  testConvertToAvroStreamForDateTime(options,
      (record, date) -> assertEquals(new Utf8(date.toString()), record.get("date")),
      (record, time) -> assertEquals(new Utf8(time.toString()), record.get("time")),
      (record, timestamp) -> assertEquals(new Utf8(timestamp.toString()), record.get("timestamp"))
  );
}

相关文章