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.hibernate.dialect.Dialect.java
protected Dialect() { log.info("Using dialect: " + this); sqlFunctions.putAll(STANDARD_AGGREGATE_FUNCTIONS); // standard sql92 functions (can be overridden by subclasses) registerFunction("substring", new SQLFunctionTemplate(Hibernate.STRING, "substring(?1, ?2, ?3)")); registerFunction("locate", new SQLFunctionTemplate(Hibernate.INTEGER, "locate(?1, ?2, ?3)")); registerFunction("trim", new SQLFunctionTemplate(Hibernate.STRING, "trim(?1 ?2 ?3 ?4)")); registerFunction("length", new StandardSQLFunction("length", Hibernate.INTEGER)); registerFunction("bit_length", new StandardSQLFunction("bit_length", Hibernate.INTEGER)); registerFunction("coalesce", new StandardSQLFunction("coalesce")); registerFunction("nullif", new StandardSQLFunction("nullif")); registerFunction("abs", new StandardSQLFunction("abs")); registerFunction("mod", new StandardSQLFunction("mod", Hibernate.INTEGER)); registerFunction("sqrt", new StandardSQLFunction("sqrt", Hibernate.DOUBLE)); registerFunction("upper", new StandardSQLFunction("upper")); registerFunction("lower", new StandardSQLFunction("lower")); registerFunction("cast", new CastFunction()); registerFunction("extract", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(?1 ?2 ?3)")); //map second/minute/hour/day/month/year to ANSI extract(), override on subclasses registerFunction("second", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(second from ?1)")); registerFunction("minute", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(minute from ?1)")); registerFunction("hour", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(hour from ?1)")); registerFunction("day", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(day from ?1)")); registerFunction("month", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(month from ?1)")); registerFunction("year", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(year from ?1)")); registerFunction("str", new SQLFunctionTemplate(Hibernate.STRING, "cast(?1 as char)")); // register hibernate types for default use in scalar sqlquery type auto detection registerHibernateType(Types.BIGINT, Hibernate.BIG_INTEGER.getName()); registerHibernateType(Types.BINARY, Hibernate.BINARY.getName()); registerHibernateType(Types.BIT, Hibernate.BOOLEAN.getName()); registerHibernateType(Types.CHAR, Hibernate.CHARACTER.getName()); registerHibernateType(Types.DATE, Hibernate.DATE.getName()); registerHibernateType(Types.DOUBLE, Hibernate.DOUBLE.getName()); registerHibernateType(Types.FLOAT, Hibernate.FLOAT.getName()); registerHibernateType(Types.INTEGER, Hibernate.INTEGER.getName()); registerHibernateType(Types.SMALLINT, Hibernate.SHORT.getName()); registerHibernateType(Types.TINYINT, Hibernate.BYTE.getName()); registerHibernateType(Types.TIME, Hibernate.TIME.getName()); registerHibernateType(Types.TIMESTAMP, Hibernate.TIMESTAMP.getName()); registerHibernateType(Types.VARCHAR, Hibernate.STRING.getName()); registerHibernateType(Types.VARBINARY, Hibernate.BINARY.getName()); registerHibernateType(Types.NUMERIC, Hibernate.BIG_DECIMAL.getName()); registerHibernateType(Types.DECIMAL, Hibernate.BIG_DECIMAL.getName()); registerHibernateType(Types.BLOB, Hibernate.BLOB.getName()); registerHibernateType(Types.CLOB, Hibernate.CLOB.getName()); registerHibernateType(Types.REAL, Hibernate.FLOAT.getName()); }
From source file:org.jumpmind.symmetric.service.impl.FileSyncService.java
public void saveFileTrigger(FileTrigger fileTrigger) { fileTrigger.setLastUpdateTime(new Date()); if (0 == sqlTemplate.update(getSql("updateFileTriggerSql"), new Object[] { fileTrigger.getBaseDir(), fileTrigger.isRecurse() ? 1 : 0, fileTrigger.getIncludesFiles(), fileTrigger.getExcludesFiles(), fileTrigger.isSyncOnCreate() ? 1 : 0, fileTrigger.isSyncOnModified() ? 1 : 0, fileTrigger.isSyncOnDelete() ? 1 : 0, fileTrigger.isSyncOnCtlFile() ? 1 : 0, fileTrigger.isDeleteAfterSync() ? 1 : 0, fileTrigger.getBeforeCopyScript(), fileTrigger.getAfterCopyScript(), fileTrigger.getLastUpdateBy(), fileTrigger.getLastUpdateTime(), fileTrigger.getChannelId(), fileTrigger.getReloadChannelId(), fileTrigger.getTriggerId() }, new int[] { Types.VARCHAR, Types.SMALLINT, Types.VARCHAR, Types.VARCHAR, Types.SMALLINT, Types.SMALLINT, Types.SMALLINT, Types.SMALLINT, Types.SMALLINT, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR })) { fileTrigger.setCreateTime(fileTrigger.getLastUpdateTime()); sqlTemplate.update(getSql("insertFileTriggerSql"), new Object[] { fileTrigger.getBaseDir(), fileTrigger.isRecurse() ? 1 : 0, fileTrigger.getIncludesFiles(), fileTrigger.getExcludesFiles(), fileTrigger.isSyncOnCreate() ? 1 : 0, fileTrigger.isSyncOnModified() ? 1 : 0, fileTrigger.isSyncOnDelete() ? 1 : 0, fileTrigger.isSyncOnCtlFile() ? 1 : 0, fileTrigger.isDeleteAfterSync() ? 1 : 0, fileTrigger.getBeforeCopyScript(), fileTrigger.getAfterCopyScript(), fileTrigger.getLastUpdateBy(), fileTrigger.getLastUpdateTime(), fileTrigger.getTriggerId(), fileTrigger.getCreateTime(), fileTrigger.getChannelId(), fileTrigger.getReloadChannelId() }, new int[] { Types.VARCHAR, Types.SMALLINT, Types.VARCHAR, Types.VARCHAR, Types.SMALLINT, Types.SMALLINT, Types.SMALLINT, Types.SMALLINT, Types.SMALLINT, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR }); }/* w ww . j av a2 s. c o m*/ }
From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectSQLServer.java
@Override public void setToPreparedStatement(PreparedStatement ps, int index, Serializable value, Column column) throws SQLException { switch (column.getJdbcType()) { case Types.VARCHAR: case Types.CLOB: setToPreparedStatementString(ps, index, value, column); return;//from w ww.jav a2 s. c om case Types.BIT: ps.setBoolean(index, ((Boolean) value).booleanValue()); return; case Types.TINYINT: case Types.INTEGER: case Types.BIGINT: ps.setLong(index, ((Number) value).longValue()); return; case Types.DOUBLE: ps.setDouble(index, ((Double) value).doubleValue()); return; case Types.TIMESTAMP: setToPreparedStatementTimestamp(ps, index, value, column); return; default: throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); } }
From source file:org.easyrec.mahout.store.impl.MahoutDataModelMappingDAOMysqlImpl.java
@Override public FastIDSet getItemIDsFromUser(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 ww . jav a2 s . c o m*/ return getJdbcTemplate().query(getItemIDsFromUserQuery, args, argTypes, fastIDSetExtractor); } catch (EmptyResultDataAccessException e) { logger.warn("An error occurred!", e); throw new NoSuchUserException(userID); } }
From source file:org.waarp.common.database.data.AbstractDbData.java
/** * Set Value into PreparedStatement/*w w w. j a va 2s .c om*/ * * @param ps * @param value * @param rank * >= 1 * @throws WaarpDatabaseSqlException */ static public void setTrueValue(PreparedStatement ps, DbValue value, int rank) throws WaarpDatabaseSqlException { try { switch (value.type) { case Types.VARCHAR: if (value.value == null) { ps.setNull(rank, Types.VARCHAR); break; } ps.setString(rank, (String) value.value); break; case Types.LONGVARCHAR: if (value.value == null) { ps.setNull(rank, Types.LONGVARCHAR); break; } ps.setString(rank, (String) value.value); break; case Types.BIT: if (value.value == null) { ps.setNull(rank, Types.BIT); break; } ps.setBoolean(rank, (Boolean) value.value); break; case Types.TINYINT: if (value.value == null) { ps.setNull(rank, Types.TINYINT); break; } ps.setByte(rank, (Byte) value.value); break; case Types.SMALLINT: if (value.value == null) { ps.setNull(rank, Types.SMALLINT); break; } ps.setShort(rank, (Short) value.value); break; case Types.INTEGER: if (value.value == null) { ps.setNull(rank, Types.INTEGER); break; } ps.setInt(rank, (Integer) value.value); break; case Types.BIGINT: if (value.value == null) { ps.setNull(rank, Types.BIGINT); break; } ps.setLong(rank, (Long) value.value); break; case Types.REAL: if (value.value == null) { ps.setNull(rank, Types.REAL); break; } ps.setFloat(rank, (Float) value.value); break; case Types.DOUBLE: if (value.value == null) { ps.setNull(rank, Types.DOUBLE); break; } ps.setDouble(rank, (Double) value.value); break; case Types.VARBINARY: if (value.value == null) { ps.setNull(rank, Types.VARBINARY); break; } ps.setBytes(rank, (byte[]) value.value); break; case Types.DATE: if (value.value == null) { ps.setNull(rank, Types.DATE); break; } ps.setDate(rank, (Date) value.value); break; case Types.TIMESTAMP: if (value.value == null) { ps.setNull(rank, Types.TIMESTAMP); break; } ps.setTimestamp(rank, (Timestamp) value.value); break; case Types.CLOB: if (value.value == null) { ps.setNull(rank, Types.CLOB); break; } ps.setClob(rank, (Reader) value.value); break; case Types.BLOB: if (value.value == null) { ps.setNull(rank, Types.BLOB); break; } ps.setBlob(rank, (InputStream) value.value); break; default: throw new WaarpDatabaseSqlException("Type not supported: " + value.type + " at " + rank); } } catch (ClassCastException e) { throw new WaarpDatabaseSqlException("Setting values casting error: " + value.type + " at " + rank, e); } catch (SQLException e) { DbSession.error(e); throw new WaarpDatabaseSqlException("Setting values in error: " + value.type + " at " + rank, e); } }
From source file:org.jumpmind.symmetric.service.impl.DataService.java
public void saveTableReloadRequest(TableReloadRequest request) { Date time = new Date(); request.setLastUpdateTime(time);/*from w ww . java 2 s . co m*/ if (0 == sqlTemplate.update(getSql("updateTableReloadRequest"), new Object[] { request.getReloadSelect(), request.getReloadDeleteStmt(), request.isReloadEnabled() ? 1 : 0, request.getReloadTime(), request.getCreateTime(), request.getLastUpdateBy(), request.getLastUpdateTime(), request.getSourceNodeId(), request.getTargetNodeId(), request.getTriggerId(), request.getRouterId() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.SMALLINT, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR })) { request.setCreateTime(time); sqlTemplate.update(getSql("insertTableReloadRequest"), new Object[] { request.getReloadSelect(), request.getReloadDeleteStmt(), request.isReloadEnabled() ? 1 : 0, request.getReloadTime(), request.getCreateTime(), request.getLastUpdateBy(), request.getLastUpdateTime(), request.getSourceNodeId(), request.getTargetNodeId(), request.getTriggerId(), request.getRouterId() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.SMALLINT, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR }); } }
From source file:org.jumpmind.symmetric.db.derby.DerbyFunctions.java
public static String getPrimaryKeyWhereString(String[] pkColumnNames, ResultSet rs) throws SQLException { final String AND = " and "; ResultSetMetaData metaData = rs.getMetaData(); StringBuilder b = new StringBuilder(); for (int i = 0; i < pkColumnNames.length; i++) { String columnName = pkColumnNames[i]; int index = findColumnIndex(metaData, columnName); int type = metaData.getColumnType(index); if (type != Types.BINARY && type != Types.BLOB && type != Types.LONGVARBINARY && type != Types.VARBINARY) { b.append("\"").append(columnName).append("\"="); switch (type) { case Types.BIT: case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: case Types.FLOAT: case Types.REAL: case Types.DOUBLE: case Types.NUMERIC: case Types.DECIMAL: case Types.BOOLEAN: b.append(rs.getObject(index)); break; case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: b.append("\"").append(rs.getString(index)).append("\""); break; case Types.DATE: case Types.TIMESTAMP: b.append("{ts '"); b.append(rs.getString(index)); b.append("'}"); break; }//from w w w . ja v a 2 s.c o m b.append(AND); } } b.replace(b.length() - AND.length(), b.length(), ""); return b.toString(); }
From source file:com.nextep.designer.sqlclient.ui.connectors.SQLResultConnector.java
private void initializeTable(ISQLQuery query, long executionTime, INextepMetadata md) { colMaxWidth = new int[md.getColumnCount() + 1]; // Checking columns to display int displayedColumns = query.getDisplayedColumnsCount(); if (displayedColumns <= 0) { displayedColumns = md.getColumnCount(); }//from ww w . jav a2 s . co m for (int i = 1; i <= displayedColumns; i++) { final String colName = md.getColumnName(i); // final int colPrecision = md.getPrecision(index); final int colType = md.getColumnType(i); final int colIndex = i - 1; if (!sqlView.isDisposed()) { TableColumn c = new TableColumn(sqlView, SWT.NONE); c.setText(colName); c.setWidth(colName.length() * 8); c.addListener(SWT.Selection, comparator); colMaxWidth[colIndex] = c.getWidth(); SQLResultLabelProvider lblProvider = new SQLResultLabelProvider(this, colIndex); final TableViewerColumn viewerCol = new TableViewerColumn(sqlViewer, c); viewerCol.setLabelProvider(lblProvider); // Registering column comparator switch (colType) { case Types.BIGINT: case Types.BIT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.INTEGER: case Types.NUMERIC: case Types.REAL: case Types.SMALLINT: case Types.TINYINT: c.setData(SQLResultViewerComparator.KEY_COMPARATOR, new NumberComparator()); // Setting our deserializer which can produce number from string c.setData(KEY_DESERIALIZER, NUMBER_DESERIALIZER); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: // Defines validation so that user will be notified about problems c.setData(KEY_CELL_VALIDATOR, DATE_VALIDATOR); // Setting our deserializer which can produce date from string c.setData(KEY_DESERIALIZER, DATE_DESERIALIZER); c.setData(SQLResultViewerComparator.KEY_COMPARATOR, new DateComparator()); break; default: c.setData(KEY_DESERIALIZER, STRING_DESERIALIZER); c.setData(SQLResultViewerComparator.KEY_COMPARATOR, new StringComparator()); } } } registerCellEditors(); setStatusLabel(MessageFormat.format(SQLClientMessages.getString("sql.executionTime"), executionTime), false); sqlViewer.setInput(query.getResult()); }
From source file:com.tesora.dve.sql.parser.TimestampVariableUtils.java
public static boolean setTimestampVariableForSpecifiedValue(PEColumn column, ExpressionNode value) { boolean ret = false; // only set the timestamp variable if this is a timestamp column if (column.getType().getBaseType().getDataType() != Types.TIMESTAMP) { return ret; }/*from www. j a va 2 s. com*/ if (value instanceof LiteralExpression) { if (((LiteralExpression) value).isNullLiteral()) { // if value is null and column is NOT nullable // then mysql will insert the current timestamp. if (!column.isNullable()) { ret = true; } } else { // user specified a literal (ie. 0 or 'yyyy-mm-dd hh:mm:ss') // so don't set the timestamp variable } } else if (value instanceof IdentifierLiteralExpression || value instanceof FunctionCall) { // for a timestamp column can only be current_timestamp ret = true; } return ret; }
From source file:org.castor.jdo.engine.SQLTypeInfos.java
/** * Set given value on given PreparedStatement at given index with given SQL type. * //from w w w.j a v a 2 s . c o m * @param stmt The PreparedStatement to set value on. * @param index The index of the value in the PreparedStatement. * @param value The value to set. * @param sqlType The SQL type of the value. */ public static void setValue(final PreparedStatement stmt, final int index, final Object value, final int sqlType) { try { if (value == null) { stmt.setNull(index, sqlType); } else { // Special processing for BLOB and CLOB types, because they are mapped // by Castor to java.io.InputStream and java.io.Reader, respectively, // while JDBC driver expects java.sql.Blob and java.sql.Clob. switch (sqlType) { case Types.FLOAT: case Types.DOUBLE: stmt.setDouble(index, ((Double) value).doubleValue()); break; case Types.REAL: stmt.setFloat(index, ((Float) value).floatValue()); break; case Types.TIME: final Time time = value instanceof java.util.Date ? new Time(((java.util.Date) value).getTime()) : null; stmt.setTime(index, time != null ? time : (Time) value, getCalendar()); break; case Types.DATE: final Date date = value instanceof java.util.Date ? new Date(((java.util.Date) value).getTime()) : null; stmt.setDate(index, date != null ? date : (Date) value); break; case Types.TIMESTAMP: final Timestamp timestamp = value instanceof java.util.Date ? new Timestamp(((java.util.Date) value).getTime()) : null; stmt.setTimestamp(index, timestamp != null ? timestamp : (Timestamp) value, getCalendar()); break; case Types.BLOB: try { InputStream stream; if (value instanceof byte[]) { stream = new ByteArrayInputStream((byte[]) value); } else { stream = (InputStream) value; } stmt.setBinaryStream(index, stream, stream.available()); } catch (IOException ex) { throw new SQLException(ex.toString()); } break; case Types.CLOB: if (value instanceof String) { stmt.setCharacterStream(index, new StringReader((String) value), Math.min(((String) value).length(), Integer.MAX_VALUE)); } else { stmt.setCharacterStream(index, ((Clob) value).getCharacterStream(), (int) Math.min(((Clob) value).length(), Integer.MAX_VALUE)); } break; default: stmt.setObject(index, value, sqlType); break; } } } catch (SQLException ex) { LOG.error("Unexpected SQL exception: ", ex); } }