List of usage examples for java.sql Time Time
public Time(long time)
Time
object using a milliseconds time value. From source file:org.botlibre.util.Utils.java
/** * Parse the time of the form, "HH:mm:ss.N". *///from ww w. j a v a 2s. c o m public static Time parseTime(String value) { try { return new Time(new SimpleDateFormat("HH:mm:ss").parse(value).getTime()); } catch (Exception exception) { return null; } }
From source file:com.taobao.adfs.database.tdhsocket.client.response.TDHSResutSet.java
public Time getTime(String columnLabel, Calendar cal) throws SQLException { Long time = ConvertUtil.getTimeFromString(this.getString(this.findColumn(columnLabel)), cal); return time == null ? null : new Time(time); }
From source file:org.kuali.coeus.propdev.impl.core.ProposalDevelopmentViewHelperServiceImpl.java
public String getDateUploadedFormatted(Timestamp uploadDate) { if (uploadDate != null) { return getDateTimeService().toDateString(new Date(uploadDate.getTime())) + " " + getDateTimeService().toTimeString(new Time(uploadDate.getTime())); }/* w w w. j ava2 s . com*/ return StringUtils.EMPTY; }
From source file:kx.c.java
Time rt() { int i = ri(); return new Time(i == ni ? nj : gl(i)); }
From source file:com.continuent.tungsten.common.mysql.MySQLPacket.java
/** * Reads a time from stream given its length and returns the corresponding * {@link Time}/*from w ww. j a va 2s . c o m*/ * * @param length size of the time data * @return jdbc Time decoded from stream */ public Time getTime(int length) { long millis = 0; boolean neg = false; if (length >= 8) { neg = (getByte() != 0); if (logger.isTraceEnabled()) logger.trace("neg=" + neg); int day = getInt32(); if (logger.isTraceEnabled()) logger.trace("day=" + day); millis = getHourMinSec(); if (length > 8) { int mil = getInt32(); if (logger.isTraceEnabled()) logger.trace("millis =" + mil % 1000); // MySQL ignores millis > 1000 (don't add the corresponding // seconds) => %1000 millis += mil % 1000; } } return new Time(neg ? -millis : millis); }
From source file:ro.nextreports.engine.queryexec.QueryExecutor.java
private void setParameterValue(PreparedStatement pstmt, Class paramValueClass, Object paramValue, int index) throws SQLException, QueryException { // for "NOT IN (?)" setting null -> result is undeterminated // ParameterUtil.NULL was good only for list of strings (for NOT IN)! if (ParameterUtil.NULL.equals(paramValue)) { paramValue = null;/*from w w w. ja va 2 s .c om*/ } if (paramValueClass.equals(Object.class)) { if (paramValue == null) { pstmt.setNull(index + 1, Types.JAVA_OBJECT); } else { if (paramValue instanceof IdName) { pstmt.setObject(index + 1, ((IdName) paramValue).getId()); } else { pstmt.setObject(index + 1, paramValue); } } } else if (paramValueClass.equals(Boolean.class)) { if (paramValue == null) { pstmt.setNull(index + 1, Types.BIT); } else { if (paramValue instanceof IdName) { pstmt.setBoolean(index + 1, (Boolean) ((IdName) paramValue).getId()); } else { pstmt.setBoolean(index + 1, (Boolean) paramValue); } } } else if (paramValueClass.equals(Byte.class)) { if (paramValue == null) { pstmt.setNull(index + 1, Types.TINYINT); } else { if (paramValue instanceof IdName) { pstmt.setByte(index + 1, (Byte) ((IdName) paramValue).getId()); } else { pstmt.setByte(index + 1, (Byte) paramValue); } } } else if (paramValueClass.equals(Double.class)) { if (paramValue == null) { pstmt.setNull(index + 1, Types.DOUBLE); } else { if (paramValue instanceof IdName) { pstmt.setDouble(index + 1, (Double) ((IdName) paramValue).getId()); } else { pstmt.setDouble(index + 1, (Double) paramValue); } } } else if (paramValueClass.equals(Float.class)) { if (paramValue == null) { pstmt.setNull(index + 1, Types.FLOAT); } else { if (paramValue instanceof IdName) { pstmt.setFloat(index + 1, (Float) ((IdName) paramValue).getId()); } else { pstmt.setFloat(index + 1, (Float) paramValue); } } } else if (paramValueClass.equals(Integer.class)) { if (paramValue == null) { pstmt.setNull(index + 1, Types.INTEGER); } else { if (paramValue instanceof IdName) { pstmt.setObject(index + 1, ((IdName) paramValue).getId()); } else { pstmt.setInt(index + 1, (Integer) paramValue); } } } else if (paramValueClass.equals(Long.class)) { if (paramValue == null) { pstmt.setNull(index + 1, Types.BIGINT); } else { if (paramValue instanceof IdName) { pstmt.setLong(index + 1, (Long) ((IdName) paramValue).getId()); } else { pstmt.setLong(index + 1, (Long) paramValue); } } } else if (paramValueClass.equals(Short.class)) { if (paramValue == null) { pstmt.setNull(index + 1, Types.SMALLINT); } else { if (paramValue instanceof IdName) { pstmt.setShort(index + 1, (Short) ((IdName) paramValue).getId()); } else { pstmt.setShort(index + 1, (Short) paramValue); } } //@todo // ParameterUtil -> values are taken from dialect (where there is no BigDecimal yet!) // or from meta data } else if (paramValueClass.equals(BigDecimal.class)) { if (paramValue == null) { pstmt.setNull(index + 1, Types.DECIMAL); } else { if (paramValue instanceof IdName) { Serializable ser = ((IdName) paramValue).getId(); if (ser instanceof BigDecimal) { pstmt.setBigDecimal(index + 1, (BigDecimal) (ser)); } else { pstmt.setInt(index + 1, (Integer) (ser)); } } else { // a simple value cannot be cast to BigDecimal! pstmt.setObject(index + 1, paramValue); } } } else if (paramValueClass.equals(BigInteger.class)) { if (paramValue == null) { pstmt.setNull(index + 1, Types.BIGINT); } else { if (paramValue instanceof IdName) { Serializable ser = ((IdName) paramValue).getId(); if (ser instanceof BigInteger) { pstmt.setBigDecimal(index + 1, new BigDecimal((BigInteger) (ser))); } else if (ser instanceof BigDecimal) { pstmt.setBigDecimal(index + 1, (BigDecimal) (ser)); } else { pstmt.setInt(index + 1, (Integer) (ser)); } } else { // a simple value cannot be cast to BigDecimal! pstmt.setObject(index + 1, paramValue); } } } else if (paramValueClass.equals(String.class)) { if (paramValue == null) { pstmt.setNull(index + 1, Types.VARCHAR); } else { if (paramValue instanceof IdName) { if (((IdName) paramValue).getId() == null) { pstmt.setNull(index + 1, Types.VARCHAR); } else { pstmt.setString(index + 1, ((IdName) paramValue).getId().toString()); } } else { pstmt.setString(index + 1, paramValue.toString()); } } } else if (paramValueClass.equals(Date.class)) { if (paramValue == null) { pstmt.setNull(index + 1, Types.DATE); } else { if (paramValue instanceof IdName) { Serializable obj = ((IdName) paramValue).getId(); Date date; if (obj instanceof String) { try { date = IdNameRenderer.sdf.parse((String) obj); } catch (ParseException e) { e.printStackTrace(); LOG.error(e.getMessage(), e); date = new Date(); } } else { date = (Date) obj; } pstmt.setDate(index + 1, new java.sql.Date(date.getTime())); } else { pstmt.setDate(index + 1, new java.sql.Date(((Date) paramValue).getTime())); } } } else if (paramValueClass.equals(Timestamp.class)) { if (paramValue == null) { pstmt.setNull(index + 1, Types.TIMESTAMP); } else { if (paramValue instanceof IdName) { Serializable obj = ((IdName) paramValue).getId(); Date date; if (obj instanceof String) { try { date = IdNameRenderer.sdf.parse((String) obj); } catch (ParseException e) { e.printStackTrace(); LOG.error(e.getMessage(), e); date = new Date(); } } else { date = (Date) obj; } pstmt.setTimestamp(index + 1, new Timestamp(date.getTime())); } else { pstmt.setTimestamp(index + 1, new Timestamp(((Date) paramValue).getTime())); } } } else if (paramValueClass.equals(Time.class)) { if (paramValue == null) { pstmt.setNull(index + 1, Types.TIME); } else { if (paramValue instanceof IdName) { Serializable obj = ((IdName) paramValue).getId(); Date date; if (obj instanceof String) { try { date = IdNameRenderer.sdf.parse((String) obj); } catch (ParseException e) { e.printStackTrace(); LOG.error(e.getMessage(), e); date = new Date(); } } else { date = (Date) obj; } pstmt.setTime(index + 1, new Time(date.getTime())); } else { pstmt.setTime(index + 1, new Time(((Date) paramValue).getTime())); } } } else { throw new QueryException("Parameter type " + paramValueClass.getName() + " not supported in query"); } // for logSql() statementParameters.put(index, paramValue); }
From source file:fr.certu.chouette.exchange.gtfs.importer.NeptuneConverter.java
/** * shift a time on and offset//from ww w. j av a 2 s. co m * * @param t * time to shift * @param offset * offset (seconds) * @return time shifted (new instance) */ private Time shiftTime(Time t, long offset) { return new Time((t.getTime() + offset) % (24 * 3600 * 1000)); }
From source file:org.apache.openjpa.jdbc.sql.DBDictionary.java
/** * Set the given value as a parameter to the statement. *///from w w w . j av a 2s.com public void setDate(PreparedStatement stmnt, int idx, Date val, Column col) throws SQLException { if (col != null && col.getType() == Types.DATE) setDate(stmnt, idx, new java.sql.Date(val.getTime()), null, col); else if (col != null && col.getType() == Types.TIME) setTime(stmnt, idx, new Time(val.getTime()), null, col); else if (val instanceof Timestamp) setTimestamp(stmnt, idx, (Timestamp) val, null, col); else setTimestamp(stmnt, idx, new Timestamp(val.getTime()), null, col); }
From source file:org.dspace.storage.rdbms.DatabaseManager.java
private static void loadParameters(PreparedStatement statement, Collection<ColumnInfo> columns, TableRow row) throws SQLException { int count = 0; for (ColumnInfo info : columns) { count++;//w w w. ja v a 2 s . c o m String column = info.getCanonicalizedName(); int jdbctype = info.getType(); if (row.isColumnNull(column)) { statement.setNull(count, jdbctype); } else { switch (jdbctype) { case Types.BIT: statement.setBoolean(count, row.getBooleanColumn(column)); break; case Types.INTEGER: if (isOracle) { statement.setLong(count, row.getLongColumn(column)); } else { statement.setInt(count, row.getIntColumn(column)); } break; case Types.NUMERIC: case Types.DECIMAL: statement.setLong(count, row.getLongColumn(column)); // FIXME should be BigDecimal if TableRow supported that break; case Types.BIGINT: statement.setLong(count, row.getLongColumn(column)); break; case Types.CLOB: if (isOracle) { // Support CLOBs in place of TEXT columns in Oracle statement.setString(count, row.getStringColumn(column)); } else { throw new IllegalArgumentException("Unsupported JDBC type: " + jdbctype); } break; case Types.VARCHAR: statement.setString(count, row.getStringColumn(column)); break; case Types.DATE: statement.setDate(count, new java.sql.Date(row.getDateColumn(column).getTime())); break; case Types.TIME: statement.setTime(count, new Time(row.getDateColumn(column).getTime())); break; case Types.TIMESTAMP: statement.setTimestamp(count, new Timestamp(row.getDateColumn(column).getTime())); break; default: throw new IllegalArgumentException("Unsupported JDBC type: " + jdbctype); } } } }
From source file:org.apache.phoenix.end2end.DateTimeIT.java
@Test public void testProjectedTimeTimestampCompare() throws Exception { String tableName = generateUniqueName(); String ddl = "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER PRIMARY KEY, times TIME, timestamps TIMESTAMP)"; conn.createStatement().execute(ddl); // Differ by date String dml = "UPSERT INTO " + tableName + " VALUES (1," + "TO_TIME('2004-02-04 00:10:10')," + "TO_TIMESTAMP('2006-04-12 00:10:10'))"; conn.createStatement().execute(dml); // Differ by time dml = "UPSERT INTO " + tableName + " VALUES (2," + "TO_TIME('2004-02-04 00:10:10'), " + "TO_TIMESTAMP('2004-02-04 15:10:20'))"; conn.createStatement().execute(dml); // Differ by nanoseconds PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?, ?, ?)"); stmt.setInt(1, 3);//from w w w . j a v a2 s . c o m stmt.setTime(2, new Time(1000)); Timestamp ts = new Timestamp(1000); ts.setNanos(100); stmt.setTimestamp(3, ts); stmt.execute(); // Equality dml = "UPSERT INTO " + tableName + " VALUES (4," + "TO_TIME('2004-02-04 00:10:10'), " + "TO_TIMESTAMP('2004-02-04 00:10:10'))"; conn.createStatement().execute(dml); conn.commit(); ResultSet rs = conn.createStatement().executeQuery("SELECT times = timestamps FROM " + tableName); assertTrue(rs.next()); assertEquals(false, rs.getBoolean(1)); assertTrue(rs.next()); assertEquals(false, rs.getBoolean(1)); assertTrue(rs.next()); assertEquals(false, rs.getBoolean(1)); assertTrue(rs.next()); assertEquals(true, rs.getBoolean(1)); assertFalse(rs.next()); }