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.sangupta.fileanalysis.db.DBResultViewer.java
private int getColumnSize(final String tableName, final String columnName, final int columnType) { // check if we have the value in database cache int size = database.getColSize(tableName, columnName); if (size > 0) { return size; }//from w ww .j av a2s . com switch (columnType) { case Types.VARCHAR: return 255; case Types.INTEGER: return 10; case Types.BOOLEAN: return 3; case Types.DOUBLE: return 14; case Types.BIGINT: return 20; case Types.TIMESTAMP: return 26; } return 10; }
From source file:org.akaza.openclinica.dao.submit.EventCRFDAO.java
public EntityBean update(EntityBean eb) { EventCRFBean ecb = (EventCRFBean) eb; ecb.setActive(false);//ww w.j a v a2 s .c om HashMap variables = new HashMap(); HashMap nullVars = new HashMap(); variables.put(new Integer(1), new Integer(ecb.getStudyEventId())); variables.put(new Integer(2), new Integer(ecb.getCRFVersionId())); if (ecb.getDateInterviewed() == null) { nullVars.put(new Integer(3), new Integer(Types.DATE)); variables.put(new Integer(3), null); } else { variables.put(new Integer(3), ecb.getDateInterviewed()); } variables.put(new Integer(4), ecb.getInterviewerName()); variables.put(new Integer(5), new Integer(ecb.getCompletionStatusId())); variables.put(new Integer(6), new Integer(ecb.getStatus().getId())); variables.put(new Integer(7), ecb.getAnnotations()); if (ecb.getDateCompleted() == null) { nullVars.put(new Integer(8), new Integer(Types.TIMESTAMP)); variables.put(new Integer(8), null); } else { variables.put(new Integer(8), new java.sql.Timestamp(ecb.getDateCompleted().getTime())); } // variables.put(new Integer(8),ecb.getDateCompleted()); variables.put(new Integer(9), new Integer(ecb.getValidatorId())); if (ecb.getDateValidate() == null) { nullVars.put(new Integer(10), new Integer(Types.DATE)); variables.put(new Integer(10), null); } else { variables.put(new Integer(10), ecb.getDateValidate()); } // variables.put(new Integer(10),ecb.getDateValidate()); if (ecb.getDateValidateCompleted() == null) { nullVars.put(new Integer(11), new Integer(Types.TIMESTAMP)); variables.put(new Integer(11), null); } else { variables.put(new Integer(11), new Timestamp(ecb.getDateValidateCompleted().getTime())); } // variables.put(new Integer(11),ecb.getDateValidateCompleted()); variables.put(new Integer(12), ecb.getValidatorAnnotations()); variables.put(new Integer(13), ecb.getValidateString()); variables.put(new Integer(14), new Integer(ecb.getStudySubjectId())); variables.put(new Integer(15), new Integer(ecb.getUpdaterId())); variables.put(new Integer(16), new Boolean(ecb.isElectronicSignatureStatus())); variables.put(new Integer(17), new Boolean(ecb.isSdvStatus())); if (ecb.getOldStatus() != null && ecb.getOldStatus().getId() > 0) { variables.put(new Integer(18), new Integer(ecb.getOldStatus().getId())); } else { variables.put(new Integer(18), new Integer(0)); } // @pgawade 22-May-2011 added the sdv updater id variable variables.put(new Integer(19), ecb.getSdvUpdateId()); // variables.put(new Integer(19), new Integer(ecb.getId())); variables.put(new Integer(21), new Integer(ecb.getId())); variables.put(new Integer(20), new Integer(ecb.getFormLayoutId())); this.execute(digester.getQuery("update"), variables, nullVars); if (isQuerySuccessful()) { ecb.setActive(true); } return ecb; }
From source file:org.apache.ddlutils.platform.mssql.MSSqlBuilder.java
/** * {@inheritDoc}//from w ww.j a va 2s . c om */ protected String getValueAsString(Column column, Object value) { if (value == null) { return "NULL"; } StringBuffer result = new StringBuffer(); switch (column.getTypeCode()) { case Types.REAL: case Types.NUMERIC: case Types.FLOAT: case Types.DOUBLE: case Types.DECIMAL: // SQL Server does not want quotes around the value if (!(value instanceof String) && (getValueNumberFormat() != null)) { result.append(getValueNumberFormat().format(value)); } else { result.append(value.toString()); } break; case Types.DATE: result.append("CAST("); result.append(getPlatformInfo().getValueQuoteToken()); result.append(value instanceof String ? (String) value : getValueDateFormat().format(value)); result.append(getPlatformInfo().getValueQuoteToken()); result.append(" AS datetime)"); break; case Types.TIME: result.append("CAST("); result.append(getPlatformInfo().getValueQuoteToken()); result.append(value instanceof String ? (String) value : getValueTimeFormat().format(value)); result.append(getPlatformInfo().getValueQuoteToken()); result.append(" AS datetime)"); break; case Types.TIMESTAMP: result.append("CAST("); result.append(getPlatformInfo().getValueQuoteToken()); result.append(value.toString()); result.append(getPlatformInfo().getValueQuoteToken()); result.append(" AS datetime)"); break; } return super.getValueAsString(column, value); }
From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectDB2.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.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); }/*from www . j a va 2s . co m*/ throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); }
From source file:at.rocworks.oa4j.logger.dbs.NoSQLJDBC.java
public int storeData(DataList list) { try {//from ww w . jav a2 s . c o m Connection conn = dataSourceWrite.getConnection(); if (conn != null) { int i; DataItem item; EventItem event; Object tag; conn.setAutoCommit(false); PreparedStatement stmt; Date t1 = new Date(); stmt = conn.prepareStatement(sqlInsertStmt); for (i = 0; i <= list.getHighWaterMark() && (item = list.getItem(i)) != null; i++) { if (!(item instanceof EventItem)) continue; event = (EventItem) item; ValueItem val = event.getValue(); tag = this.getTagOfDp(event.getDp()); if (tag == null) continue; if (tag instanceof Long) stmt.setLong(1, (Long) tag); else if (tag instanceof String) stmt.setString(1, (String) tag); java.sql.Timestamp ts = new java.sql.Timestamp(event.getTimeMS()); ts.setNanos(event.getNanos()); stmt.setTimestamp(2, ts, cal); Double dval = val.getDouble(); if (dval != null) { stmt.setDouble(3, dval); } else { stmt.setNull(3, Types.DOUBLE); } // value_string stmt.setString(4, val.getString()); // value_timestamp if (val.getTimeMS() != null) stmt.setTimestamp(5, new java.sql.Timestamp(val.getTimeMS()), cal); else stmt.setNull(5, Types.TIMESTAMP); // status, manager, user if (event.hasAttributes()) { stmt.setLong(6, event.getStatus()); stmt.setInt(7, event.getManager()); stmt.setInt(8, event.getUser()); } else { stmt.setNull(6, Types.INTEGER); stmt.setNull(7, Types.INTEGER); stmt.setNull(8, Types.INTEGER); } //JDebug.out.log(Level.FINE, "{0}:{1}/{2} [{3}]", new Object[] {i, element_id.toString(), ts.toString(), item.toString()}); stmt.addBatch(); } try { stmt.executeBatch(); // TODO check result? int[] res = } catch (BatchUpdateException ex) { JDebug.out.log(Level.SEVERE, "Batch exception {0} update count {1}.", new Object[] { ex.getErrorCode(), ex.getUpdateCounts().length }); JDebug.StackTrace(Level.SEVERE, ex); } catch (SQLException ex) { SQLException current = ex; do { JDebug.out.log(Level.SEVERE, "SQL exception {0}.", new Object[] { ex.getErrorCode() }); JDebug.StackTrace(Level.SEVERE, current); } while ((current = current.getNextException()) != null); // for (i = 0; i <= list.getHighWaterMark() && (item = list.getItem(i)) != null; i++) { // JDebug.out.log(Level.INFO, "{0}", item.toJSONObject()); // } } Date t2 = new Date(); stmt.close(); afterInsert(conn); conn.commit(); conn.close(); addServerStats(list.getHighWaterMark(), t2.getTime() - t1.getTime()); return INoSQLInterface.OK; } else { JDebug.StackTrace(Level.SEVERE, "no connection!"); return INoSQLInterface.ERR_REPEATABLE; } } catch (Exception ex) { JDebug.StackTrace(Level.SEVERE, ex); return INoSQLInterface.ERR_REPEATABLE; } }
From source file:org.batoo.jpa.jdbc.adapter.HsqlAdaptor.java
/** * {@inheritDoc}/* w w w . ja va 2 s .co m*/ * */ @Override protected String getColumnType(AbstractColumn cd, int sqlType) { switch (sqlType) { case Types.BLOB: case Types.CLOB: return "VARBINARY(" + cd.getLength() + ")"; case Types.VARCHAR: return "VARCHAR(" + cd.getLength() + ")"; case Types.TIME: return "TIME"; case Types.DATE: return "DATE"; case Types.TIMESTAMP: return "TIMESTAMP"; case Types.CHAR: return "CHAR"; case Types.BOOLEAN: return "BOOLEAN"; case Types.TINYINT: case Types.SMALLINT: return "SMALLINT"; case Types.INTEGER: return "INTEGER"; case Types.BIGINT: return "BIGINT"; case Types.FLOAT: return "FLOAT" + (cd.getPrecision() > 0 ? "(" + cd.getPrecision() + ")" : ""); case Types.DOUBLE: return "DOUBLE" + (cd.getPrecision() > 0 ? "(" + cd.getPrecision() + ")" : ""); case Types.DECIMAL: return "DECIMAL" + (cd.getPrecision() > 0 ? "(" + cd.getPrecision() + (cd.getScale() > 0 ? "," + cd.getScale() : "") + ")" : ""); } throw new IllegalArgumentException("Unhandled sql type: " + sqlType); }
From source file:co.nubetech.apache.hadoop.DateSplitter.java
/** Parse the long-valued timestamp into the appropriate SQL date type. */ private Date longToDate(long val, int sqlDataType) { switch (sqlDataType) { case Types.DATE: return new java.sql.Date(val); case Types.TIME: return new java.sql.Time(val); case Types.TIMESTAMP: return new java.sql.Timestamp(val); default: // Shouldn't ever hit this case. return null; }/*from w w w. jav a2s. co m*/ }
From source file:org.jumpmind.symmetric.service.impl.AbstractDataExtractorServiceTest.java
protected void save(TestExtract obj) { String updateSql = String.format( "update %s set varchar_value=?, longvarchar_value=?, timestamp_value=?, date_value=?, bit_value=?, bigint_value=?, decimal_value=? where id=?", TEST_TABLE);/*from w ww . j a v a 2 s . co m*/ String insertSql = String.format( "insert into %s (varchar_value, longvarchar_value, timestamp_value, date_value, bit_value, bigint_value, decimal_value, id) values(?,?,?,?,?,?,?,?)", TEST_TABLE); if (0 == getSqlTemplate().update(updateSql, new Object[] { obj.getVarcharValue(), obj.getLongVarcharValue(), obj.getTimestampValue(), obj.getDateValue(), obj.isBitValue(), obj.getBigIntValue(), obj.getDecimalValue(), obj.getId() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.DATE, Types.BIT, Types.NUMERIC, Types.NUMERIC, Types.NUMERIC })) { getSqlTemplate().update(insertSql, new Object[] { obj.getVarcharValue(), obj.getLongVarcharValue(), obj.getTimestampValue(), obj.getDateValue(), obj.isBitValue(), obj.getBigIntValue(), obj.getDecimalValue(), obj.getId() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.DATE, Types.BIT, Types.NUMERIC, Types.NUMERIC, Types.NUMERIC }); } }
From source file:org.easyrec.store.dao.plugin.impl.LogEntryDAOMysqlImpl.java
protected LogEntryDAOMysqlImpl(DataSource dataSource, SqlScriptService sqlScriptService, PluginRegistry pluginRegistry) { super(sqlScriptService); setDataSource(dataSource);//from w w w . j a v a 2 s .c o m startEntry = new SqlUpdate(dataSource, "INSERT INTO plugin_log(tenantId, pluginId, pluginVersion, startDate, assocTypeId, " + "configuration) VALUES (?, ?, ?, ?, ?, ?)", new int[] { Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR, Types.BLOB }); startEntry.compile(); endEntry = new SqlUpdate(dataSource, "INSERT INTO plugin_log(tenantId, pluginId, pluginVersion, startDate, assocTypeId, configuration, " + "endDate, statistics) VALUES (?, ?, ?, ?, ?, ?, ?, ?) " + "ON DUPLICATE KEY UPDATE endDate = ?, statistics = ?", new int[] { Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR, Types.BLOB, Types.TIMESTAMP, Types.BLOB, Types.TIMESTAMP, Types.BLOB }); endEntry.compile(); endAllEntries = new SqlUpdate(dataSource, "UPDATE plugin_log SET endDate = ?, statistics = ? WHERE endDate IS NULL", new int[] { Types.TIMESTAMP, Types.BLOB }); endAllEntries.compile(); getRunningTenants = new MappingSqlQuery<Integer>(dataSource, "SELECT tenantId FROM plugin_log WHERE endDate IS NULL") { @Override protected Integer mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getInt("tenantId"); } }; getRunningTenants.compile(); getLogEntries = new GetLogEntriesStatement(dataSource, pluginRegistry, "SELECT * FROM plugin_log ORDER BY endDate DESC, id DESC LIMIT ?, ?"); getLogEntries.declareParameter(new SqlParameter("offset", Types.INTEGER)); getLogEntries.declareParameter(new SqlParameter("limit", Types.INTEGER)); getLogEntries.compile(); getLogEntriesForTenant = new GetLogEntriesStatement(dataSource, pluginRegistry, "SELECT * FROM plugin_log WHERE tenantId = ? ORDER BY startDate DESC, id DESC LIMIT ?, ?"); getLogEntriesForTenant.declareParameter(new SqlParameter("tenantId", Types.INTEGER)); getLogEntriesForTenant.declareParameter(new SqlParameter("offset", Types.INTEGER)); getLogEntriesForTenant.declareParameter(new SqlParameter("limit", Types.INTEGER)); getLogEntriesForTenant.compile(); getLogEntriesWithAssocType = new GetLogEntriesStatement(dataSource, pluginRegistry, "SELECT * FROM plugin_log WHERE assocTypeId = ? ORDER BY startDate DESC, id DESC LIMIT ?, ?"); getLogEntriesWithAssocType.declareParameter(new SqlParameter("assocTypeId", Types.INTEGER)); getLogEntriesWithAssocType.declareParameter(new SqlParameter("offset", Types.INTEGER)); getLogEntriesWithAssocType.declareParameter(new SqlParameter("limit", Types.INTEGER)); getLogEntriesWithAssocType.compile(); getLogEntriesForTenantWithAssocType = new GetLogEntriesStatement(dataSource, pluginRegistry, "SELECT * FROM plugin_log WHERE tenantId = ? AND assocTypeId = ? ORDER BY startDate DESC, id DESC LIMIT ?, ?"); getLogEntriesForTenantWithAssocType.declareParameter(new SqlParameter("tenantId", Types.INTEGER)); getLogEntriesForTenantWithAssocType.declareParameter(new SqlParameter("assocTypeId", Types.INTEGER)); getLogEntriesForTenantWithAssocType.declareParameter(new SqlParameter("offset", Types.INTEGER)); getLogEntriesForTenantWithAssocType.declareParameter(new SqlParameter("limit", Types.INTEGER)); getLogEntriesForTenantWithAssocType.compile(); getNumberOfLogEntries = new SqlFunction<Integer>(dataSource, "SELECT count(*) AS entry_count FROM plugin_log"); getNumberOfLogEntries.compile(); getNumberOfLogEntriesForTenant = new SqlFunction<Integer>(dataSource, "SELECT count(*) AS entry_count FROM plugin_log WHERE tenantId = ?"); getNumberOfLogEntriesForTenant.setResultType(Integer.class); getNumberOfLogEntriesForTenant.declareParameter(new SqlParameter("tenantId", Types.INTEGER)); getNumberOfLogEntriesForTenant.compile(); deleteLogEntries = new SqlUpdate(dataSource, "TRUNCATE plugin_log"); deleteLogEntries.compile(); getComputationDurationForDate = new SqlFunction<Integer>(dataSource, "SELECT sum(timestampdiff(second, startDate, endDate)) AS sum_seconds FROM plugin_log WHERE endDate BETWEEN ? AND ?"); getComputationDurationForDate.setResultType(Integer.class); getComputationDurationForDate.declareParameter(new SqlParameter("start", Types.DATE)); getComputationDurationForDate.declareParameter(new SqlParameter("end", Types.DATE)); getComputationDurationForDate.compile(); deleteLogEntryStatement = new SqlUpdate(dataSource, "DELETE FROM plugin_log WHERE tenantId = ? AND pluginId = ? AND pluginVersion = ? AND startDate = ? AND assocTypeId = ?"); deleteLogEntryStatement.declareParameter(new SqlParameter("tenantId", Types.INTEGER)); deleteLogEntryStatement.declareParameter(new SqlParameter("pluginId", Types.VARCHAR)); deleteLogEntryStatement.declareParameter(new SqlParameter("pluginVersion", Types.VARCHAR)); deleteLogEntryStatement.declareParameter(new SqlParameter("startDate", Types.TIMESTAMP)); deleteLogEntryStatement.declareParameter(new SqlParameter("assocTypeId", Types.VARCHAR)); deleteLogEntryStatement.compile(); }