Java Code Examples for java.sql.Time#valueOf()

The following examples show how to use java.sql.Time#valueOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HiveORCSearchArgumentBuilder.java    From pxf with Apache License 2.0 5 votes vote down vote up
/**
 * Converts the string value to the given type
 *
 * @param dataType the data type
 * @param value    the value
 * @return the string value to the given type
 */
private Object convertDataType(DataType dataType, String value) {
    try {
        switch (dataType) {
            case BIGINT:
                return Long.parseLong(value);
            case INTEGER:
            case SMALLINT:
                return Integer.parseInt(value);
            case REAL:
                return Float.parseFloat(value);
            case NUMERIC:
            case FLOAT8:
                return Double.parseDouble(value);
            case TEXT:
            case VARCHAR:
            case BPCHAR:
                return value;
            case BOOLEAN:
                return Boolean.parseBoolean(value);
            case DATE:
                return Date.valueOf(value);
            case TIMESTAMP:
                return Timestamp.valueOf(value);
            case TIME:
                return Time.valueOf(value);
            case BYTEA:
                return value.getBytes();
            default:
                throw new UnsupportedTypeException(String.format("DataType %s unsupported", dataType));
        }
    } catch (NumberFormatException nfe) {
        throw new IllegalStateException(String.format("failed to parse number data %s for type %s", value, dataType));
    }
}
 
Example 2
Source File: TimeTests.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test19() {
    Time t = Time.valueOf("08:30:59");
    Time t2 = new Time(t.getTime());
    assertFalse(t.after(t2), "Error t.after(t2) = true");
    assertFalse(t2.after(t), "Error t2.after(t) = true");
}
 
Example 3
Source File: Oracle11DialectTest.java    From doma with Apache License 2.0 5 votes vote down vote up
@Test
public void testTimeFormat() throws Exception {
  Oracle11Dialect dialect = new Oracle11Dialect();
  SqlLogFormattingVisitor visitor = dialect.getSqlLogFormattingVisitor();
  TimeWrapper wrapper = new TimeWrapper(Time.valueOf("01:23:45"));
  assertEquals("time'01:23:45'", wrapper.accept(visitor, new ConvertToLogFormatFunction(), null));
}
 
Example 4
Source File: TimeConversionUtil.java    From enkan with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 文字列を{@link Time}に変換します。
 *
 * @param str
 *            文字列
 * @return 変換された{@link Time}
 */
protected static Time toSqlTimeJdbcEscape(final String str) {
    try {
        return Time.valueOf(str);
    } catch (final IllegalArgumentException ex) {
        return null;
    }
}
 
Example 5
Source File: TimeTests.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test21() {
    Time t = Time.valueOf("08:30:59");
    Time t2 = new Time(System.currentTimeMillis());
    assertTrue(t.before(t2), "Error t.before(t2) = false");
}
 
Example 6
Source File: TimeTests.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "invalidTimeValues",
        expectedExceptions = IllegalArgumentException.class)
public void test16(String time) throws Exception {
    Time.valueOf(time);
}
 
Example 7
Source File: TimeTests.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test20() {
    Time t = Time.valueOf("08:30:59");
    assertFalse(t.before(t), "Error t.before(t) = true");
}
 
Example 8
Source File: TimeTests.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = IllegalArgumentException.class)
public void test07() {
    Time t = Time.valueOf("08:30:59");
    t.setDate(30);
}
 
Example 9
Source File: TimeTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test15() {
    Time t = Time.valueOf("08:30:59");
    Time t2 = new Time(t.getTime());
    assertTrue(t.equals(t2) && t2.equals(t), "Error t != t2");
}
 
Example 10
Source File: TimeTests.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = IllegalArgumentException.class)
public void test06() {
    Time t = Time.valueOf("08:30:59");
    t.setMonth(8);
}
 
Example 11
Source File: TimeTests.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = IllegalArgumentException.class)
public void test05() {
    Time t = Time.valueOf("08:30:59");
    t.setYear(8);
}
 
Example 12
Source File: JsonRowDeserializationSchema.java    From flink with Apache License 2.0 4 votes vote down vote up
private Time convertToTime(ObjectMapper mapper, JsonNode jsonNode) {
	return Time.valueOf(convertToLocalTime(mapper, jsonNode));
}
 
Example 13
Source File: TimeTests.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = IllegalArgumentException.class)
public void test03() {
    Time t = Time.valueOf("08:30:59");
    t.getDay();
}
 
Example 14
Source File: TimeTests.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = NullPointerException.class)
public void test11() throws Exception {
    LocalTime ld = null;
    Time.valueOf(ld);
}
 
Example 15
Source File: TimeTests.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test20() {
    Time t = Time.valueOf("08:30:59");
    assertFalse(t.before(t), "Error t.before(t) = true");
}
 
Example 16
Source File: TimeTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "invalidTimeValues",
        expectedExceptions = IllegalArgumentException.class)
public void test16(String time) throws Exception {
    Time.valueOf(time);
}
 
Example 17
Source File: TimeTests.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test17() {
    Time t = Time.valueOf("08:30:59");
    assertFalse(t.after(t), "Error t.after(t) = true");
}
 
Example 18
Source File: TimeTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = IllegalArgumentException.class)
public void test01() {
    Time t = Time.valueOf("08:30:59");
    t.getYear();
}
 
Example 19
Source File: TimeTests.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test15() {
    Time t = Time.valueOf("08:30:59");
    Time t2 = new Time(t.getTime());
    assertTrue(t.equals(t2) && t2.equals(t), "Error t != t2");
}
 
Example 20
Source File: TimeTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = IllegalArgumentException.class)
public void test08() {
    Time t = Time.valueOf("08:30:59");
    t.getDate();
}