List of usage examples for java.sql Types TIMESTAMP
int TIMESTAMP
To view the source code for java.sql Types TIMESTAMP.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIMESTAMP
.
From source file:org.apache.hadoop.sqoop.manager.SqlManager.java
public String toJavaType(int sqlType) { // mappings from http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html if (sqlType == Types.INTEGER) { return "Integer"; } else if (sqlType == Types.VARCHAR) { return "String"; } else if (sqlType == Types.CHAR) { return "String"; } else if (sqlType == Types.LONGVARCHAR) { return "String"; } else if (sqlType == Types.NUMERIC) { return "java.math.BigDecimal"; } else if (sqlType == Types.DECIMAL) { return "java.math.BigDecimal"; } else if (sqlType == Types.BIT) { return "Boolean"; } else if (sqlType == Types.BOOLEAN) { return "Boolean"; } else if (sqlType == Types.TINYINT) { return "Integer"; } else if (sqlType == Types.SMALLINT) { return "Integer"; } else if (sqlType == Types.BIGINT) { return "Long"; } else if (sqlType == Types.REAL) { return "Float"; } else if (sqlType == Types.FLOAT) { return "Double"; } else if (sqlType == Types.DOUBLE) { return "Double"; } else if (sqlType == Types.DATE) { return "java.sql.Date"; } else if (sqlType == Types.TIME) { return "java.sql.Time"; } else if (sqlType == Types.TIMESTAMP) { return "java.sql.Timestamp"; } else {//from w w w. j av a2 s . c o m // TODO(aaron): Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT, CLOB, BLOB, ARRAY, // STRUCT, REF, JAVA_OBJECT. return null; } }
From source file:org.easyrec.mahout.store.impl.MahoutDataModelMappingDAOMysqlImpl.java
@Override public PreferenceArray getPreferencesFromUser(int tenantId, Date cutoffDate, long userID, int actionTypeId) throws TasteException { Object[] args = new Object[] { tenantId, cutoffDate, userID, actionTypeId }; int[] argTypes = new int[] { Types.INTEGER, Types.TIMESTAMP, Types.INTEGER, Types.INTEGER }; try {/* w w w. j ava 2 s.com*/ return new GenericUserPreferenceArray(getJdbcTemplate().query(getPreferencesFromUserQuery, args, argTypes, genericPreferenceRowMapper)); } catch (EmptyResultDataAccessException e) { logger.warn("An error occurred!", e); throw new NoSuchUserException(userID); } }
From source file:org.jumpmind.symmetric.service.impl.OutgoingBatchService.java
public void updateOutgoingBatch(ISqlTransaction transaction, OutgoingBatch outgoingBatch) { outgoingBatch.setLastUpdatedTime(new Date()); outgoingBatch.setLastUpdatedHostName(clusterService.getServerId()); transaction.prepareAndExecute(getSql("updateOutgoingBatchSql"), new Object[] { outgoingBatch.getStatus().name(), outgoingBatch.getLoadId(), outgoingBatch.isExtractJobFlag() ? 1 : 0, outgoingBatch.isLoadFlag() ? 1 : 0, outgoingBatch.isErrorFlag() ? 1 : 0, outgoingBatch.getByteCount(), outgoingBatch.getExtractCount(), outgoingBatch.getSentCount(), outgoingBatch.getLoadCount(), outgoingBatch.getDataEventCount(), outgoingBatch.getReloadEventCount(), outgoingBatch.getInsertEventCount(), outgoingBatch.getUpdateEventCount(), outgoingBatch.getDeleteEventCount(), outgoingBatch.getOtherEventCount(), outgoingBatch.getIgnoreCount(), outgoingBatch.getRouterMillis(), outgoingBatch.getNetworkMillis(), outgoingBatch.getFilterMillis(), outgoingBatch.getLoadMillis(), outgoingBatch.getExtractMillis(), outgoingBatch.getSqlState(), outgoingBatch.getSqlCode(), FormatUtils.abbreviateForLogging(outgoingBatch.getSqlMessage()), outgoingBatch.getFailedDataId(), outgoingBatch.getLastUpdatedHostName(), outgoingBatch.getLastUpdatedTime(), outgoingBatch.getBatchId(), outgoingBatch.getNodeId() }, new int[] { Types.CHAR, Types.BIGINT, Types.NUMERIC, Types.NUMERIC, Types.NUMERIC, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.VARCHAR, Types.NUMERIC, Types.VARCHAR, Types.BIGINT, Types.VARCHAR, Types.TIMESTAMP, symmetricDialect.getSqlTypeForIds(), Types.VARCHAR }); }
From source file:org.sakaiproject.webservices.SakaiReport.java
protected String toCsvString(ResultSet rs, boolean includeHeaderRow) throws IOException, SQLException { StringWriter stringWriter = new StringWriter(); CsvWriter writer = new CsvWriter(stringWriter, ','); writer.setRecordDelimiter('\n'); writer.setForceQualifier(true);/*from w w w. j av a 2s .co m*/ ResultSetMetaData rsmd = rs.getMetaData(); int numColumns = rsmd.getColumnCount(); if (includeHeaderRow) { String[] row = new String[numColumns]; for (int i = 1; i < numColumns + 1; i++) { row[i - 1] = rsmd.getColumnLabel(i); } writer.writeRecord(row); } while (rs.next()) { String[] row = new String[numColumns]; for (int i = 1; i < numColumns + 1; i++) { String column_name = rsmd.getColumnName(i); LOG.debug("Column Name=" + column_name + ",type=" + rsmd.getColumnType(i)); switch (rsmd.getColumnType(i)) { case Types.BIGINT: row[i - 1] = String.valueOf(rs.getInt(i)); break; case Types.BOOLEAN: row[i - 1] = String.valueOf(rs.getBoolean(i)); break; case Types.BLOB: row[i - 1] = rs.getBlob(i).toString(); break; case Types.DOUBLE: row[i - 1] = String.valueOf(rs.getDouble(i)); break; case Types.FLOAT: row[i - 1] = String.valueOf(rs.getFloat(i)); break; case Types.INTEGER: row[i - 1] = String.valueOf(rs.getInt(i)); break; case Types.LONGVARCHAR: row[i - 1] = rs.getString(i); break; case Types.NVARCHAR: row[i - 1] = rs.getNString(i); break; case Types.VARCHAR: row[i - 1] = rs.getString(i); break; case Types.TINYINT: row[i - 1] = String.valueOf(rs.getInt(i)); break; case Types.SMALLINT: row[i - 1] = String.valueOf(rs.getInt(i)); break; case Types.DATE: row[i - 1] = rs.getDate(i).toString(); break; case Types.TIMESTAMP: row[i - 1] = rs.getTimestamp(i).toString(); break; default: row[i - 1] = rs.getString(i); break; } LOG.debug("value: " + row[i - 1]); } writer.writeRecord(row); //writer.endRecord(); } LOG.debug("csv output:" + stringWriter.toString()); return stringWriter.toString(); }
From source file:org.seasar.dbflute.logic.replaceschema.loaddata.impl.DfAbsractDataWriter.java
protected boolean processNull(String tableName, String columnName, Object value, PreparedStatement ps, int bindCount, Map<String, DfColumnMeta> columnInfoMap) throws SQLException { if (!isNullValue(value)) { return false; }// w w w.j a va 2 s. c o m Map<String, Integer> cacheMap = _nullTypeCacheMap.get(tableName); if (cacheMap == null) { cacheMap = StringKeyMap.createAsFlexibleOrdered(); _nullTypeCacheMap.put(tableName, cacheMap); } final Integer cachedType = cacheMap.get(columnName); if (cachedType != null) { // cache hit ps.setNull(bindCount, cachedType); // basically no exception return true; } final DfColumnMeta columnInfo = columnInfoMap.get(columnName); if (columnInfo != null) { // use mapped type at first final String mappedJdbcType = _columnHandler.getColumnJdbcType(columnInfo); final Integer mappedJdbcDefValue = TypeMap.getJdbcDefValueByJdbcType(mappedJdbcType); try { ps.setNull(bindCount, mappedJdbcDefValue); cacheMap.put(columnName, mappedJdbcDefValue); } catch (SQLException e) { // retry by plain type final int plainJdbcDefValue = columnInfo.getJdbcDefValue(); try { ps.setNull(bindCount, plainJdbcDefValue); cacheMap.put(columnName, plainJdbcDefValue); } catch (SQLException ignored) { final ExceptionMessageBuilder br = new ExceptionMessageBuilder(); br.addNotice("Failed to execute setNull(bindCount, jdbcDefValue)."); br.addItem("Column"); br.addElement(tableName + "." + columnName); br.addElement(columnInfo.toString()); br.addItem("Mapped JDBC Type"); br.addElement(mappedJdbcType); br.addItem("First JDBC Def-Value"); br.addElement(mappedJdbcDefValue); br.addItem("Retry JDBC Def-Value"); br.addElement(plainJdbcDefValue); br.addItem("Retry Message"); br.addElement(ignored.getMessage()); String msg = br.buildExceptionMessage(); throw new DfJDBCException(msg, e); } } } else { // basically no way Integer tryType = Types.VARCHAR; // as default try { ps.setNull(bindCount, tryType); cacheMap.put(columnName, tryType); } catch (SQLException e) { tryType = Types.NUMERIC; try { ps.setNull(bindCount, tryType); cacheMap.put(columnName, tryType); } catch (SQLException ignored) { tryType = Types.TIMESTAMP; try { ps.setNull(bindCount, tryType); cacheMap.put(columnName, tryType); } catch (SQLException iignored) { tryType = Types.OTHER; try { ps.setNull(bindCount, tryType); // last try cacheMap.put(columnName, tryType); } catch (SQLException iiignored) { throw e; } } } } } return true; }
From source file:com.squid.core.domain.operators.ExtendedType.java
/** * compute a type "order" that can be used to compare types and promote types. * The order is a couple (x,y), where x represent a family type (string,date,numbers) and y an order in that family * A type should be promoted to the higher order. * @return/*ww w . jav a2 s . co m*/ */ public int[] computeTypeOrder() { switch (getDataType()) { case Types.BIT: return new int[] { NUMBER_ORDER, 0 }; case Types.BOOLEAN: return new int[] { NUMBER_ORDER, 1 }; case Types.TINYINT: return new int[] { NUMBER_ORDER, 2 }; case Types.SMALLINT: return new int[] { NUMBER_ORDER, 3 }; case Types.INTEGER: return new int[] { NUMBER_ORDER, 4 }; case Types.BIGINT: return new int[] { NUMBER_ORDER, 5 }; /////////////////////////// case Types.REAL: return new int[] { NUMBER_ORDER, 6 }; case Types.DOUBLE: case Types.FLOAT: return new int[] { NUMBER_ORDER, 7 }; case Types.DECIMAL: return new int[] { NUMBER_ORDER, 8 }; case Types.NUMERIC: return new int[] { NUMBER_ORDER, 9 }; ////////////////////////// case Types.CHAR: return new int[] { STRING_ORDER, 0 }; case Types.VARCHAR: return new int[] { STRING_ORDER, 1 }; case Types.LONGVARCHAR: return new int[] { STRING_ORDER, 2 }; case Types.CLOB: return new int[] { STRING_ORDER, 3 }; /////////////////////////// case Types.TIME: return new int[] { DATE_ORDER, 1 }; case Types.DATE: return new int[] { DATE_ORDER, 2 }; case Types.TIMESTAMP: return new int[] { DATE_ORDER, 3 }; case CustomTypes.INTERVAL: return new int[] { DATE_ORDER, 4 }; /////////////////////////// default: return new int[] { UNKNOWN_ORDER, 0 }; } }
From source file:org.apache.sqoop.tool.ImportTool.java
/** * Initialize the constraints which set the incremental import range. * @return false if an import is not necessary, because the dataset has not * changed./* w w w. j a va 2s . com*/ */ private boolean initIncrementalConstraints(SqoopOptions options, ImportJobContext context) throws ImportException, IOException { // If this is an incremental import, determine the constraints // to inject in the WHERE clause or $CONDITIONS for a query. // Also modify the 'last value' field of the SqoopOptions to // specify the current job start time / start row. if (!isIncremental(options)) { return true; } SqoopOptions.IncrementalMode incrementalMode = options.getIncrementalMode(); String nextIncrementalValue = null; Object nextVal; switch (incrementalMode) { case AppendRows: try { nextVal = getMaxColumnId(options); if (isDateTimeColumn(checkColumnType)) { nextIncrementalValue = (nextVal == null) ? null : manager.datetimeToQueryString(nextVal.toString(), checkColumnType); } else { nextIncrementalValue = (nextVal == null) ? null : nextVal.toString(); } } catch (SQLException sqlE) { throw new IOException(sqlE); } break; case DateLastModified: checkColumnType = Types.TIMESTAMP; nextVal = manager.getCurrentDbTimestamp(); if (null == nextVal) { throw new IOException("Could not get current time from database"); } nextIncrementalValue = manager.datetimeToQueryString(nextVal.toString(), checkColumnType); break; default: throw new ImportException("Undefined incremental import type: " + incrementalMode); } // Build the WHERE clause components that are used to import // only this incremental section. StringBuilder sb = new StringBuilder(); String prevEndpoint = options.getIncrementalLastValue(); if (isDateTimeColumn(checkColumnType) && null != prevEndpoint && !prevEndpoint.startsWith("\'") && !prevEndpoint.endsWith("\'")) { // Incremental imports based on date/time should be 'quoted' in // ANSI SQL. If the user didn't specify single-quotes, put them // around, here. prevEndpoint = manager.datetimeToQueryString(prevEndpoint, checkColumnType); } String checkColName = manager.escapeColName(options.getIncrementalTestColumn()); LOG.info("Incremental import based on column " + checkColName); if (null != prevEndpoint) { if (prevEndpoint.equals(nextIncrementalValue)) { LOG.info("No new rows detected since last import."); return false; } LOG.info("Lower bound value: " + prevEndpoint); sb.append(checkColName); switch (incrementalMode) { case AppendRows: sb.append(" > "); break; case DateLastModified: sb.append(" >= "); break; default: throw new ImportException("Undefined comparison"); } sb.append(prevEndpoint); sb.append(" AND "); } if (null != nextIncrementalValue) { sb.append(checkColName); switch (incrementalMode) { case AppendRows: sb.append(" <= "); break; case DateLastModified: sb.append(" < "); break; default: throw new ImportException("Undefined comparison"); } sb.append(nextIncrementalValue); } else { sb.append(checkColName); sb.append(" IS NULL "); } LOG.info("Upper bound value: " + nextIncrementalValue); if (options.getTableName() != null) { // Table based import String prevWhereClause = options.getWhereClause(); if (null != prevWhereClause) { sb.append(" AND ("); sb.append(prevWhereClause); sb.append(")"); } String newConstraints = sb.toString(); options.setWhereClause(newConstraints); } else { // Incremental based import sb.append(" AND $CONDITIONS"); String newQuery = options.getSqlQuery().replace("$CONDITIONS", sb.toString()); options.setSqlQuery(newQuery); } // Save this state for next time. SqoopOptions recordOptions = options.getParent(); if (null == recordOptions) { recordOptions = options; } recordOptions.setIncrementalLastValue((nextVal == null) ? null : nextVal.toString()); return true; }
From source file:org.latticesoft.util.resource.dao.Param.java
private Object readValue(ResultSet rs) throws SQLException { Object retVal = null;/*from w ww . j a va 2 s .com*/ switch (this.sqlType) { case Types.VARCHAR: case Types.CHAR: String s = null; if (this.getSqlIndex() == 0) { s = rs.getString(this.getSqlName()); } else { s = rs.getString(this.getSqlIndex()); } retVal = s; break; case Types.BOOLEAN: boolean b = false; if (this.getSqlIndex() == 0) { b = rs.getBoolean(this.getSqlName()); } else { b = rs.getBoolean(this.getSqlIndex()); } retVal = new Boolean(b); break; case Types.INTEGER: int i = 0; if (this.getSqlIndex() == 0) { i = rs.getInt(this.getSqlName()); } else { i = rs.getInt(this.getSqlIndex()); } retVal = new Integer(i); break; case Types.SMALLINT: short ss = 0; if (this.getSqlIndex() == 0) { ss = rs.getShort(this.getSqlName()); } else { ss = rs.getShort(this.getSqlIndex()); } retVal = new Short(ss); break; case Types.TINYINT: byte bb = 0; if (this.getSqlIndex() == 0) { bb = rs.getByte(this.getSqlName()); } else { bb = rs.getByte(this.getSqlIndex()); } retVal = new Byte(bb); break; case Types.BIGINT: long l = 0; if (this.getSqlIndex() == 0) { l = rs.getLong(this.getSqlName()); } else { l = rs.getLong(this.getSqlIndex()); } retVal = new Long(l); break; case Types.DOUBLE: double dd = 0; if (this.getSqlIndex() == 0) { dd = rs.getDouble(this.getSqlName()); } else { dd = rs.getDouble(this.getSqlIndex()); } retVal = new Double(dd); break; case Types.FLOAT: float f = 0; if (this.getSqlIndex() == 0) { f = rs.getFloat(this.getSqlName()); } else { f = rs.getFloat(this.getSqlIndex()); } retVal = new Float(f); break; case Types.NUMERIC: BigDecimal bd = null; if (this.getSqlIndex() == 0) { bd = rs.getBigDecimal(this.getSqlName()); } else { bd = rs.getBigDecimal(this.getSqlIndex()); } retVal = bd; break; case Types.TIMESTAMP: Timestamp ts = null; if (this.getSqlIndex() == 0) { ts = rs.getTimestamp(this.getSqlName()); } else { ts = rs.getTimestamp(this.getSqlIndex()); } retVal = ts; break; default: if (this.getSqlIndex() == 0) { retVal = rs.getObject(this.getSqlName()); } else { retVal = rs.getObject(this.getSqlIndex()); } break; } if (log.isDebugEnabled()) { log.debug(this.getAttribute() + "=" + retVal); } return retVal; }
From source file:org.apache.sqoop.hcat.HCatalogExportTest.java
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),//from ww w .ja v a 2 s.com 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); }
From source file:jp.co.tis.gsp.tools.dba.dialect.MysqlDialect.java
@Override public void setObjectInStmt(PreparedStatement stmt, int parameterIndex, String value, int sqlType) throws SQLException { if (sqlType == UN_USABLE_TYPE) { stmt.setNull(parameterIndex, Types.NULL); } else if (StringUtil.isBlank(value) || "".equals(value)) { stmt.setNull(parameterIndex, sqlType); } else if (sqlType == Types.TIMESTAMP) { stmt.setTimestamp(parameterIndex, Timestamp.valueOf(value)); } else {//from www .j a va2 s . com stmt.setObject(parameterIndex, value, sqlType); } }