本文整理汇总了Java中java.sql.Date类的典型用法代码示例。如果您正苦于以下问题:Java Date类的具体用法?Java Date怎么用?Java Date使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Date类属于java.sql包,在下文中一共展示了Date类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBug54095
import java.sql.Date; //导入依赖的package包/类
/**
* 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();
}
示例2: PreparedStmtSetValue
import java.sql.Date; //导入依赖的package包/类
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);
}
}
示例3: testDateTypesToBigInt
import java.sql.Date; //导入依赖的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);
}
示例4: testLogin
import java.sql.Date; //导入依赖的package包/类
@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);
}
示例5: testGetTaskCountByWorkbasketAndDaysInPastAndState
import java.sql.Date; //导入依赖的package包/类
@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));
}
示例6: generateTestDataFileForPartitionInput
import java.sql.Date; //导入依赖的package包/类
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();
}
示例7: date2Obj
import java.sql.Date; //导入依赖的package包/类
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));
}
}
示例8: testCrearPassword
import java.sql.Date; //导入依赖的package包/类
@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());
}
示例9: setParam
import java.sql.Date; //导入依赖的package包/类
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);
}
}
示例10: setDate
import java.sql.Date; //导入依赖的package包/类
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);
}
}
示例11: getNormalisedTimestamp
import java.sql.Date; //导入依赖的package包/类
public static Timestamp getNormalisedTimestamp(Date d) {
synchronized (tempCalDefault) {
setTimeInMillis(tempCalDefault, d.getTime());
resetToDate(tempCalDefault);
long value = getTimeInMillis(tempCalDefault);
return new Timestamp(value);
}
}
示例12: appendLog
import java.sql.Date; //导入依赖的package包/类
@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('\'');
}
示例13: setDate
import java.sql.Date; //导入依赖的package包/类
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);
}
}
示例14: testGetPredicateForDate
import java.sql.Date; //导入依赖的package包/类
/**
* 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);
}
示例15: getNormalisedDate
import java.sql.Date; //导入依赖的package包/类
public static Date getNormalisedDate(Date d) {
synchronized (tempCalDefault) {
setTimeInMillis(tempCalDefault, d.getTime());
resetToDate(tempCalDefault);
long value = getTimeInMillis(tempCalDefault);
return new Date(value);
}
}