本文整理汇总了Java中java.sql.Time类的典型用法代码示例。如果您正苦于以下问题:Java Time类的具体用法?Java Time怎么用?Java Time使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Time类属于java.sql包,在下文中一共展示了Time类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: changeType
import java.sql.Time; //导入依赖的package包/类
/**
* Changes the type of the source to a Float object;
*/
@Override
protected Float changeType(Class<?> sourceClass, Object source) {
if (Number.class.isAssignableFrom(sourceClass))
return ((Number) source).floatValue();
else if (Date.class.isAssignableFrom(sourceClass))
return (float) ((Date) source).getTime();
else if (java.sql.Date.class.isAssignableFrom(sourceClass))
return (float) ((java.sql.Date) source).getTime();
else if (Time.class.isAssignableFrom(sourceClass))
return (float) ((Time) source).getTime();
else if (Timestamp.class.isAssignableFrom(sourceClass))
return (float) ((Timestamp) source).getTime();
else
return super.changeType(sourceClass, source);
}
示例2: checkPreparedStatementForTestBug50348
import java.sql.Time; //导入依赖的package包/类
private void checkPreparedStatementForTestBug50348(Connection testConn, Timestamp timestamp, Time time, String expectedTimestamp, String expectedTime)
throws SQLException {
PreparedStatement testPstmt = testConn.prepareStatement("SELECT ?, ?");
testPstmt.setTimestamp(1, timestamp);
testPstmt.setTime(2, time);
this.rs = testPstmt.executeQuery();
this.rs.next();
String timestampAsString = new String(this.rs.getBytes(1));
String timeAsString = new String(this.rs.getBytes(2));
String alert = expectedTimestamp.equals(timestampAsString) && expectedTime.equals(timeAsString) ? "" : " <-- (!)";
System.out.printf("[PS] expected: '%s' | '%s'%n", expectedTimestamp, expectedTime);
System.out.printf(" actual: '%s' | '%s' %s%n", timestampAsString, timeAsString, alert);
assertEquals(expectedTimestamp, timestampAsString);
assertEquals(expectedTime, timeAsString);
}
示例3: apply
import java.sql.Time; //导入依赖的package包/类
@Override
void apply(PreparedStatement stmt, int stmtIndex, DataFrameRow<R, C> row) {
final R rowKey = row.key();
try {
switch (rowKeyType) {
case BIT: stmt.setBoolean(stmtIndex, rowKeyMapper.applyAsBoolean(rowKey)); break;
case BOOLEAN: stmt.setBoolean(stmtIndex, rowKeyMapper.applyAsBoolean(rowKey)); break;
case TINYINT: stmt.setInt(stmtIndex, rowKeyMapper.applyAsInt(rowKey)); break;
case SMALLINT: stmt.setInt(stmtIndex, rowKeyMapper.applyAsInt(rowKey)); break;
case FLOAT: stmt.setDouble(stmtIndex, rowKeyMapper.applyAsDouble(rowKey)); break;
case INTEGER: stmt.setInt(stmtIndex, rowKeyMapper.applyAsInt(rowKey)); break;
case BIGINT: stmt.setLong(stmtIndex, rowKeyMapper.applyAsLong(rowKey)); break;
case DOUBLE: stmt.setDouble(stmtIndex, rowKeyMapper.applyAsDouble(rowKey)); break;
case DECIMAL: stmt.setDouble(stmtIndex, rowKeyMapper.applyAsDouble(rowKey)); break;
case VARCHAR: stmt.setString(stmtIndex, (String)rowKeyMapper.apply(rowKey)); break;
case DATE: stmt.setDate(stmtIndex, (Date)rowKeyMapper.apply(rowKey)); break;
case TIME: stmt.setTime(stmtIndex, (Time)rowKeyMapper.apply(rowKey)); break;
case DATETIME: stmt.setTimestamp(stmtIndex, (Timestamp)rowKeyMapper.apply(rowKey)); break;
default: throw new IllegalStateException("Unsupported column type:" + rowKeyType);
}
} catch (Exception ex) {
throw new DataFrameException("Failed to apply row key to SQL statement at " + rowKey, ex);
}
}
示例4: testDateTypesToBigInt
import java.sql.Time; //导入依赖的package包/类
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);
}
示例5: setTimeInternal
import java.sql.Time; //导入依赖的package包/类
/**
* Set a parameter to a java.sql.Time value. The driver converts this to a
* SQL TIME value when it sends it to the database, using the given
* timezone.
*
* @param parameterIndex
* the first parameter is 1...));
* @param x
* the parameter value
* @param tz
* the timezone to use
*
* @throws java.sql.SQLException
* if a database access error occurs
*/
private void setTimeInternal(int parameterIndex, Time x, Calendar targetCalendar, TimeZone tz, boolean rollForward) throws java.sql.SQLException {
if (x == null) {
setNull(parameterIndex, java.sql.Types.TIME);
} else {
checkClosed();
if (!this.useLegacyDatetimeCode) {
newSetTimeInternal(parameterIndex, x, targetCalendar);
} else {
Calendar sessionCalendar = getCalendarInstanceForSessionOrNew();
x = TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, x, tz, this.connection.getServerTimezoneTZ(), rollForward);
setInternal(parameterIndex, "'" + x.toString() + "'");
}
this.parameterTypes[parameterIndex - 1 + getParameterIndexOffset()] = Types.TIME;
}
}
示例6: appendTime
import java.sql.Time; //导入依赖的package包/类
/**
* Appends a time to the underlying command;
*
* @param time
* @return
*/
public DatabaseCommand appendTime(Time time) {
this.text.append('\'');
this.text.append(time);
this.text.append('\'');
return this;
}
示例7: createFactHeader
import java.sql.Time; //导入依赖的package包/类
void createFactHeader(int nFactId, int nClientId)
{
Date date = new Date();
Time time = new Time(date.getTime());
String csDate = String.valueOf(time);
sql("insert into VIT102 (ID, CLIENTID, FACTDATE) VALUES (#1, #2, #3)")
.value(1, nFactId)
.value(2, nClientId)
.value(3, csDate);
}
示例8: getNormalisedTimestamp
import java.sql.Time; //导入依赖的package包/类
public static Timestamp getNormalisedTimestamp(Time t) {
synchronized (tempCalDefault) {
setTimeInMillis(tempCalDefault, System.currentTimeMillis());
resetToDate(tempCalDefault);
long value = getTimeInMillis(tempCalDefault) + t.getTime();
return new Timestamp(value);
}
}
示例9: changeType
import java.sql.Time; //导入依赖的package包/类
/**
* Changes the type of the source object to this adapter's data type;
*/
@Override
protected Time changeType(Class<?> sourceClass, Object source) {
if (Date.class.isAssignableFrom(sourceClass))
return new Time(((Date) source).getTime());
else if (Number.class.isAssignableFrom(sourceClass))
return new Time(((Number) source).longValue());
else
return super.changeType(sourceClass, source);
}
示例10: baseRowSetTest0014
import java.sql.Time; //导入依赖的package包/类
@Test()
public void baseRowSetTest0014() throws Exception {
Calendar cal = Calendar.getInstance();
brs = new StubBaseRowSet();
brs.setTime(1, Time.valueOf(LocalTime.now()), cal);
assertTrue(checkCalendarParam(1, cal));
}
示例11: getTime
import java.sql.Time; //导入依赖的package包/类
public Time getTime(String parameterName, Calendar cal) throws SQLException {
try {
if (this.wrappedStmt != null) {
return ((CallableStatement) this.wrappedStmt).getTime(parameterName, cal);
}
throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);
} catch (SQLException sqlEx) {
checkAndFireConnectionError(sqlEx);
}
return null;
}
示例12: getTimeFast
import java.sql.Time; //导入依赖的package包/类
@Override
public Time getTimeFast(int columnIndex, Calendar targetCalendar, TimeZone tz, boolean rollForward, MySQLConnection conn, ResultSetImpl rs)
throws SQLException {
if (isNull(columnIndex)) {
return null;
}
findAndSeekToOffset(columnIndex);
long length = this.rowFromServer.readFieldLength();
int offset = this.rowFromServer.getPosition();
return getTimeFast(columnIndex, this.rowFromServer.getByteBuffer(), offset, (int) length, targetCalendar, tz, rollForward, conn, rs);
}
示例13: getTimeFast
import java.sql.Time; //导入依赖的package包/类
@Override
public Time getTimeFast(int columnIndex, Calendar targetCalendar, TimeZone tz, boolean rollForward, MySQLConnection conn, ResultSetImpl rs)
throws SQLException {
byte[] columnValue = this.internalRowData[columnIndex];
if (columnValue == null) {
return null;
}
return getTimeFast(columnIndex, this.internalRowData[columnIndex], 0, columnValue.length, targetCalendar, tz, rollForward, conn, rs);
}
示例14: testGetTimeLabel
import java.sql.Time; //导入依赖的package包/类
@Test
public void testGetTimeLabel() throws SQLException
{
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
cal.clear();
cal.set(1970, 0, 1, 14, 6, 15);
assertNotNull(subject.getTime(TIME_COL_NOT_NULL));
assertEquals(new Time(cal.getTimeInMillis()), subject.getTime(TIME_COL_NOT_NULL));
assertEquals(false, subject.wasNull());
assertNull(subject.getTime(TIME_COL_NULL));
assertTrue(subject.wasNull());
}
示例15: hour
import java.sql.Time; //导入依赖的package包/类
/**
* Returns the hour from the given time value, as an integer value in
* the range of 0-23.
*
* @param t the time value from which to extract the hour of day
* @return the hour of day from the given time value
*/
// [email protected] 20020210 - patch 513005 by [email protected] (RMP) - hour
public static Integer hour(Time t) {
if (t == null) {
return null;
}
return ValuePool.getInt(HsqlDateTime.getDateTimePart(t,
Calendar.HOUR_OF_DAY));
}