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:com.btobits.automator.ant.sql.task.SQLCompareTask.java
private void verify() throws Exception { final LinkedList<SQLCompareTask.VerifyCell> rows = impl.getVerifySqls(); for (final SQLCompareTask.VerifyCell sqlRow : rows) { sqlRow.validate();//from w ww .ja va2s. co m switch (getColumnType(sqlRow)) { case Types.DOUBLE: { final Double val = (Double) getRowValue(sqlRow); if (val == null) { errors.add("Error compare row, row not exist [" + sqlRow.toString() + "]."); } final DoubleValidator doubleValidator = new DoubleValidator(); if (doubleValidator.isValid(sqlRow.getValue())) { final Double dbValue = doubleValidator.validate(sqlRow.getValue()); if (!dbValue.equals(val)) { errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField() + "], value [" + sqlRow.getValue() + " != " + val + "]"); } } else { errors.add("Error cast field [" + sqlRow.toString() + "] to Double value."); } } break; case Types.FLOAT: { final Float val = (Float) getRowValue(sqlRow); if (val == null) { errors.add("Error compare row, row not exist [" + sqlRow.toString() + "]."); } final FloatValidator validator = new FloatValidator(); if (validator.isValid(sqlRow.getValue())) { final Float dbValue = validator.validate(sqlRow.getValue()); if (!dbValue.equals(val)) { errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField() + "], value [" + sqlRow.getValue() + " != " + val + "]"); } } else { errors.add("Error cast field [" + sqlRow.toString() + "] to Float value."); } } break; case Types.DECIMAL: { final BigDecimal val = (BigDecimal) getRowValue(sqlRow); if (val == null) { errors.add("Error compare row, row not exist [" + sqlRow.toString() + "]."); } final BigDecimalValidator validator = new BigDecimalValidator(); if (validator.isValid(sqlRow.getValue())) { BigDecimal dbValue = validator.validate(sqlRow.getValue()); dbValue = dbValue.setScale(val.scale()); if (!dbValue.equals(val)) { errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField() + "], value [" + sqlRow.getValue() + " != " + val + "]"); } } else { errors.add("Error cast field [" + sqlRow.toString() + "] to Decimal value."); } } break; case Types.DATE: { final Date val = (Date) getDateRowValue(sqlRow); if (val == null) { errors.add("Error compare row, row not exist [" + sqlRow.toString() + "]."); } final DateValidator validator = DateValidator.getInstance(); if (validator.isValid(sqlRow.getValue(), "yyyy-MM-dd")) { final Date dbValue = validator.validate(sqlRow.getValue(), "yyyy-MM-dd"); if (!dbValue.equals(val)) { errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField() + "], value [" + sqlRow.getValue() + " != " + val + "]"); } } else { errors.add("Error cast field [" + sqlRow.toString() + "] to Date value."); } } break; case Types.TIME: { final Date val = (Date) getTimeRowValue(sqlRow); if (val == null) { errors.add("Error compare row, row not exist [" + sqlRow.toString() + "]."); } final TimeValidator validator = TimeValidator.getInstance(); if (validator.isValid(sqlRow.getValue(), "HH:mm:ss")) { final Calendar dbValue = validator.validate(sqlRow.getValue(), "HH:mm:ss"); final Calendar dbVal = Calendar.getInstance(); dbVal.setTime(val); if (validator.compareHours(dbValue, dbVal) != 0 || validator.compareMinutes(dbValue, dbVal) != 0 || validator.compareSeconds(dbValue, dbVal) != 0) { errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField() + "], value [" + sqlRow.getValue() + " != " + val + "]"); } } else { errors.add("Error cast field [" + sqlRow.toString() + "] to Time value."); } } break; case Types.TIMESTAMP: { final Date val = getDateTimeRowValue(sqlRow); if (val == null) { errors.add("Error compare row, row not exist [" + sqlRow.toString() + "]."); } final CalendarValidator validatorDate = CalendarValidator.getInstance(); final TimeValidator validatorTime = TimeValidator.getInstance(); if (validatorDate.isValid(sqlRow.getValue(), "yyyy-MM-dd HH:mm:ss")) { final Calendar dbValue = validatorDate.validate(sqlRow.getValue(), "yyyy-MM-dd HH:mm:ss"); final Calendar dbVal = Calendar.getInstance(); dbVal.setTimeInMillis(val.getTime()); if (validatorDate.compareDates(dbVal, dbValue) != 0 || validatorTime.compareHours(dbValue, dbVal) != 0 || validatorTime.compareMinutes(dbValue, dbVal) != 0 || validatorTime.compareSeconds(dbValue, dbVal) != 0) { errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField() + "], value [" + sqlRow.getValue() + " != " + val + "]"); } } else { errors.add("Error cast field [" + sqlRow.toString() + "] to Timestamp value."); } } break; default: { final String dbValue = getStringRowValue(sqlRow); if (dbValue == null) { errors.add("Error compare row, row not exist [" + sqlRow.toString() + "]."); } else if (!StringUtils.equals(sqlRow.getValue(), dbValue)) { errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField() + "], value [" + sqlRow.getValue() + " != " + dbValue + "]"); } } } } }
From source file:org.fireflow.engine.persistence.springjdbc.PersistenceServiceSpringJdbcImpl.java
/** * ? Save processInstance/* w w w .j ava2s .co m*/ * @param processInstance */ public void saveOrUpdateProcessInstance(IProcessInstance processInstance) { // ?ID?nullnullcreate?update // ??????? String processInstanceId = null; if (processInstance.getId() == null || processInstance.getId().trim().equals("")) { // ???? StringBuffer sql = new StringBuffer(); sql.append("INSERT "); sql.append("INTO T_FF_RT_PROCESSINSTANCE "); sql.append(" ( "); sql.append(" id , "); sql.append(" process_id , "); sql.append(" version , "); sql.append(" name , "); sql.append(" display_name , "); sql.append(" state , "); sql.append(" suspended , "); sql.append(" creator_id , "); sql.append(" created_time , "); sql.append(" started_time , "); sql.append(" expired_time , "); sql.append(" end_time , "); sql.append(" parent_processinstance_id, "); sql.append(" parent_taskinstance_id "); sql.append(" ) "); sql.append(" VALUES "); sql.append(" ( "); sql.append(" ?, "); sql.append(" ?, "); sql.append(" ?, "); sql.append(" ?, "); sql.append(" ?, "); sql.append(" ?, "); sql.append(" ?, "); sql.append(" ?, "); sql.append(" ?, "); sql.append(" ?, "); sql.append(" ?, "); sql.append(" ?, "); sql.append(" ?, "); sql.append(" ? "); sql.append(" )"); if (show_sql) { System.out.println("FIREWORKFLOW_JDCB:" + sql.toString()); } processInstanceId = java.util.UUID.randomUUID().toString().replace("-", ""); ((ProcessInstance) processInstance).setId(processInstanceId); // ? super.getJdbcTemplate().update(sql.toString(), new Object[] { processInstanceId, processInstance.getProcessId(), processInstance.getVersion(), processInstance.getName(), processInstance.getDisplayName(), processInstance.getState(), processInstance.isSuspended() == true ? 1 : 0, processInstance.getCreatorId(), getSqlDateTime(processInstance.getCreatedTime()), getSqlDateTime(processInstance.getStartedTime()), getSqlDateTime(processInstance.getExpiredTime()), getSqlDateTime(processInstance.getEndTime()), processInstance.getParentProcessInstanceId(), processInstance.getParentTaskInstanceId() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.TIMESTAMP, Types.TIMESTAMP, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR }); } else { // ? StringBuffer sql = new StringBuffer(); sql.append("UPDATE T_FF_RT_PROCESSINSTANCE "); sql.append("SET process_id = ?, "); sql.append(" version = ?, "); sql.append(" name = ?, "); sql.append(" display_name = ?, "); sql.append(" state = ?, "); sql.append(" suspended = ?, "); sql.append(" creator_id = ?, "); sql.append(" created_time = ?, "); sql.append(" started_time = ?, "); sql.append(" expired_time = ?, "); sql.append(" end_time = ?, "); sql.append(" parent_processinstance_id = ?, "); sql.append(" parent_taskinstance_id = ? "); sql.append("WHERE ID =?"); if (show_sql) { System.out.println("FIREWORKFLOW_JDCB:" + sql.toString()); } processInstanceId = processInstance.getId(); super.getJdbcTemplate().update(sql.toString(), new Object[] { processInstance.getProcessId(), processInstance.getVersion(), processInstance.getName(), processInstance.getDisplayName(), processInstance.getState(), processInstance.isSuspended() == true ? 1 : 0, processInstance.getCreatorId(), getSqlDateTime(processInstance.getCreatedTime()), getSqlDateTime(processInstance.getStartedTime()), getSqlDateTime(processInstance.getExpiredTime()), getSqlDateTime(processInstance.getEndTime()), processInstance.getParentProcessInstanceId(), processInstance.getParentTaskInstanceId(), processInstance.getId() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.TIMESTAMP, Types.TIMESTAMP, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR }); } }
From source file:CreateNewType.java
private static Vector getDataTypes(Connection con, String typeToCreate) throws SQLException { String structName = null, distinctName = null, javaName = null; // create a vector of class DataType initialized with // the SQL code, the SQL type name, and two null entries // for the local type name and the creation parameter(s) Vector dataTypes = new Vector(); dataTypes.add(new DataType(java.sql.Types.BIT, "BIT")); dataTypes.add(new DataType(java.sql.Types.TINYINT, "TINYINT")); dataTypes.add(new DataType(java.sql.Types.SMALLINT, "SMALLINT")); dataTypes.add(new DataType(java.sql.Types.INTEGER, "INTEGER")); dataTypes.add(new DataType(java.sql.Types.BIGINT, "BIGINT")); dataTypes.add(new DataType(java.sql.Types.FLOAT, "FLOAT")); dataTypes.add(new DataType(java.sql.Types.REAL, "REAL")); dataTypes.add(new DataType(java.sql.Types.DOUBLE, "DOUBLE")); dataTypes.add(new DataType(java.sql.Types.NUMERIC, "NUMERIC")); dataTypes.add(new DataType(java.sql.Types.DECIMAL, "DECIMAL")); dataTypes.add(new DataType(java.sql.Types.CHAR, "CHAR")); dataTypes.add(new DataType(java.sql.Types.VARCHAR, "VARCHAR")); dataTypes.add(new DataType(java.sql.Types.LONGVARCHAR, "LONGVARCHAR")); dataTypes.add(new DataType(java.sql.Types.DATE, "DATE")); dataTypes.add(new DataType(java.sql.Types.TIME, "TIME")); dataTypes.add(new DataType(java.sql.Types.TIMESTAMP, "TIMESTAMP")); dataTypes.add(new DataType(java.sql.Types.BINARY, "BINARY")); dataTypes.add(new DataType(java.sql.Types.VARBINARY, "VARBINARY")); dataTypes.add(new DataType(java.sql.Types.LONGVARBINARY, "LONGVARBINARY")); dataTypes.add(new DataType(java.sql.Types.NULL, "NULL")); dataTypes.add(new DataType(java.sql.Types.OTHER, "OTHER")); dataTypes.add(new DataType(java.sql.Types.BLOB, "BLOB")); dataTypes.add(new DataType(java.sql.Types.CLOB, "CLOB")); DatabaseMetaData dbmd = con.getMetaData(); ResultSet rs = dbmd.getTypeInfo(); while (rs.next()) { int codeNumber = rs.getInt("DATA_TYPE"); String dbmsName = rs.getString("TYPE_NAME"); String createParams = rs.getString("CREATE_PARAMS"); if (codeNumber == Types.STRUCT && structName == null) structName = dbmsName;// w ww. j a v a 2s. c o m else if (codeNumber == Types.DISTINCT && distinctName == null) distinctName = dbmsName; else if (codeNumber == Types.JAVA_OBJECT && javaName == null) javaName = dbmsName; else { for (int i = 0; i < dataTypes.size(); i++) { // find entry that matches the SQL code, // and if local type and params are not already set, // set them DataType type = (DataType) dataTypes.get(i); if (type.getCode() == codeNumber) { type.setLocalTypeAndParams(dbmsName, createParams); } } } } if (typeToCreate.equals("s")) { int[] types = { Types.STRUCT, Types.DISTINCT, Types.JAVA_OBJECT }; rs = dbmd.getUDTs(null, "%", "%", types); while (rs.next()) { String typeName = null; DataType dataType = null; if (dbmd.isCatalogAtStart()) typeName = rs.getString(1) + dbmd.getCatalogSeparator() + rs.getString(2) + "." + rs.getString(3); else typeName = rs.getString(2) + "." + rs.getString(3) + dbmd.getCatalogSeparator() + rs.getString(1); switch (rs.getInt(5)) { case Types.STRUCT: dataType = new DataType(Types.STRUCT, typeName); dataType.setLocalTypeAndParams(structName, null); break; case Types.DISTINCT: dataType = new DataType(Types.DISTINCT, typeName); dataType.setLocalTypeAndParams(distinctName, null); break; case Types.JAVA_OBJECT: dataType = new DataType(Types.JAVA_OBJECT, typeName); dataType.setLocalTypeAndParams(javaName, null); break; } dataTypes.add(dataType); } } return dataTypes; }
From source file:org.nuxeo.ecm.core.storage.sql.db.dialect.DialectPostgreSQL.java
@Override @SuppressWarnings("boxing") public Serializable getFromResultSet(ResultSet rs, int index, Column column) throws SQLException { switch (column.getJdbcType()) { case Types.VARCHAR: case Types.CLOB: String string = rs.getString(index); if (column.getType() == ColumnType.BLOBID && string != null) { return column.getModel().getBinary(string); } else {//from w ww .ja v a 2 s. c o m return string; } case Types.BIT: return rs.getBoolean(index); case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: return rs.getLong(index); case Types.DOUBLE: return rs.getDouble(index); case Types.TIMESTAMP: Timestamp ts = rs.getTimestamp(index); if (ts == null) { return null; } else { Serializable cal = new GregorianCalendar(); // XXX timezone ((Calendar) cal).setTimeInMillis(ts.getTime()); return cal; } case Types.ARRAY: return (Serializable) rs.getArray(index).getArray(); } throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); }
From source file:org.opennms.core.db.install.Column.java
/** * <p>getColumnSqlType</p>/* w w w . ja va2 s . co m*/ * * @return a int. * @throws java.lang.Exception if any. */ public int getColumnSqlType() throws Exception { if (m_type.equals("integer")) { return Types.INTEGER; } else if (m_type.equals("smallint")) { return Types.SMALLINT; } else if (m_type.equals("bigint")) { return Types.BIGINT; } else if (m_type.equals("real")) { return Types.REAL; } else if (m_type.equals("double precision")) { return Types.DOUBLE; } else if (m_type.equals("boolean")) { return Types.BOOLEAN; } else if (m_type.equals("character")) { return Types.CHAR; } else if (m_type.equals("character varying")) { return Types.VARCHAR; } else if (m_type.equals("bpchar")) { return Types.VARCHAR; } else if (m_type.equals("numeric")) { return Types.NUMERIC; } else if (m_type.equals("text")) { return Types.LONGVARCHAR; } else if (m_type.equals("timestamp")) { return Types.TIMESTAMP; } else if (m_type.equals("timestamptz")) { return Types.TIMESTAMP; } else if (m_type.equals("bytea")) { return Types.VARBINARY; } else { throw new Exception("Do not have a Java SQL type for \"" + m_type + "\""); } }
From source file:org.brucalipto.sqlutil.SQLManager.java
/** * Method useful for SQL SELECT// ww w . j a va 2 s . c o m * @param preparedStatement The prepared statement to execute * @param parameters List of {@link SQLParameter} to use to complete the prepared statement * @return Returns a RowSetDynaClass containing returned rows * @throws SQLException */ public RowSetDynaClass dynaSelect(final String preparedStatement, final SQLParameter[] params) throws SQLException { final long elapsedTime = System.currentTimeMillis(); SQLParameter[] parameters; if (params == null) { parameters = new SQLParameter[0]; log.debug("Going to execute a query without parameters."); } else { parameters = (SQLParameter[]) params.clone(); } Connection dbConn = null; PreparedStatement pstmt = null; ResultSet rs = null; try { if (this.dataSource != null) { dbConn = this.dataSource.getConnection(); } else { dbConn = this.connection; } pstmt = dbConn.prepareStatement(preparedStatement); for (int i = 0; i < parameters.length; i++) { final SQLParameter param = parameters[i]; log.debug((i + 1) + ") Going to add parameter " + param); final int sqlType = param.getSqlType(); final Object paramValue = param.getValue(); if (paramValue == null) { pstmt.setNull(i + 1, sqlType); continue; } switch (sqlType) { case Types.VARCHAR: pstmt.setString(i + 1, (String) paramValue); break; case Types.INTEGER: if (paramValue instanceof Integer) { pstmt.setInt(i + 1, ((Integer) paramValue).intValue()); } else if (paramValue instanceof Long) { pstmt.setLong(i + 1, ((Long) paramValue).longValue()); } break; case Types.DATE: pstmt.setDate(i + 1, (Date) paramValue); break; case Types.BOOLEAN: pstmt.setBoolean(i + 1, ((Boolean) paramValue).booleanValue()); break; case Types.CHAR: pstmt.setString(i + 1, ((Character) paramValue).toString()); break; case Types.DOUBLE: pstmt.setDouble(i + 1, ((Double) paramValue).doubleValue()); break; case Types.FLOAT: pstmt.setFloat(i + 1, ((Float) paramValue).floatValue()); break; case Types.TIMESTAMP: pstmt.setTimestamp(i + 1, (Timestamp) paramValue); break; default: pstmt.setObject(i + 1, paramValue); break; } } rs = pstmt.executeQuery(); RowSetDynaClass rowSetDynaClass = new RowSetDynaClass(rs, false); if (log.isDebugEnabled()) { log.debug("Prepared statement '" + preparedStatement + "' returned '" + rowSetDynaClass.getRows().size() + "' rows in '" + (System.currentTimeMillis() - elapsedTime) + "' millis with following properties:"); DynaProperty[] properties = rowSetDynaClass.getDynaProperties(); for (int i = 0; i < properties.length; i++) { log.debug("Name: '" + properties[i].getName() + "'; Type: '" + properties[i].getType().getName() + "'"); } } return rowSetDynaClass; } catch (SQLException e) { log.error("Error executing prepared statement '" + preparedStatement + "'", e); throw e; } finally { closeResources(rs, pstmt, dbConn); } }
From source file:com.bt.aloha.batchtest.PerformanceMeasurmentDao.java
public boolean record(String name, long runId, Metrics m) throws IllegalStateException { if (!exists) { log.warn("record skipped as schema does not exists"); return false; }/*from ww w. ja va 2 s .c o m*/ long id = generateId(); String desc = m.getDescription() == null ? "" : m.getDescription().substring(0, Math.min(4096, m.getDescription().length())); Object[] args = new Object[] { id, runId, name, m.getUnitsPerSecond(), m.getAverageDuration(), m.getNumberOfRuns(), m.getNumberOfSuccessfulRuns(), m.getVariance(), m.getStandardDeviation(), new Timestamp(System.currentTimeMillis()), m.isSuccess(), desc, m.getThreadInfo(), m.getTestType() }; int[] types = new int[] { Types.BIGINT, Types.BIGINT, Types.VARCHAR, Types.DOUBLE, Types.DOUBLE, Types.BIGINT, Types.BIGINT, Types.DOUBLE, Types.DOUBLE, Types.TIMESTAMP, Types.BOOLEAN, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR }; try { int updated = jdbcTemplate.update( "insert into Performance (id, runid, name, unitPerSecond, averageDuration, numberOfRuns, " + "numberOfSuccessfulRuns, variance, standardDeviation, whenCreated, success, description, threadInfo, testType) " + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", args, types); if (updated < 1) log.warn("no rows inserted into performance table"); return updated == 1; } catch (RuntimeException e) { throw new IllegalStateException("Unable to record data", e); } }
From source file:org.eclipse.ecr.core.storage.sql.jdbc.dialect.DialectPostgreSQL.java
@Override @SuppressWarnings("boxing") public Serializable getFromResultSet(ResultSet rs, int index, Column column) throws SQLException { switch (column.getJdbcType()) { case Types.VARCHAR: case Types.CLOB: return getFromResultSetString(rs, index, column); case Types.BIT: return rs.getBoolean(index); case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: return rs.getLong(index); case Types.DOUBLE: return rs.getDouble(index); case Types.TIMESTAMP: return getFromResultSetTimestamp(rs, index, column); case Types.ARRAY: Array array = rs.getArray(index); return array == null ? null : (Serializable) array.getArray(); }/* w w w. j a v a 2s . c o m*/ throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); }
From source file:org.eclipse.ecr.core.storage.sql.jdbc.dialect.DialectOracle.java
@Override @SuppressWarnings("boxing") public Serializable getFromResultSet(ResultSet rs, int index, Column column) throws SQLException { switch (column.getJdbcType()) { case Types.VARCHAR: return getFromResultSetString(rs, index, column); case Types.CLOB: // Oracle cannot read CLOBs using rs.getString when the ResultSet is // a ScrollableResultSet (the standard OracleResultSetImpl works // fine). Reader r = rs.getCharacterStream(index); if (r == null) { return null; }//from w w w. j a v a 2s. c o m StringBuilder sb = new StringBuilder(); try { int n; char[] buffer = new char[4096]; while ((n = r.read(buffer)) != -1) { sb.append(new String(buffer, 0, n)); } } catch (IOException e) { log.error("Cannot read CLOB", e); } return sb.toString(); case Types.BIT: return rs.getBoolean(index); case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: return rs.getLong(index); case Types.DOUBLE: return rs.getDouble(index); case Types.TIMESTAMP: return getFromResultSetTimestamp(rs, index, column); } throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); }
From source file:org.apache.sqoop.tool.ImportTool.java
/** * Determine if a column is date/time./*www .j a v a 2s .c om*/ * @return true if column type is TIMESTAMP, DATE, or TIME. */ private boolean isDateTimeColumn(int columnType) { return (columnType == Types.TIMESTAMP) || (columnType == Types.DATE) || (columnType == Types.TIME); }