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:nl.ordina.bag.etl.dao.AbstractBAGDAO.java
@Override public void insert(final Pand pand) throws DAOException { try {/*from w w w .j a va 2 s . c o m*/ jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement("insert into bag_pand (" + "bag_pand_id," + "aanduiding_record_inactief," + "aanduiding_record_correctie," + "officieel," + "pand_geometrie," + "bouwjaar," + "pand_status," + "begindatum_tijdvak_geldigheid," + "einddatum_tijdvak_geldigheid," + "in_onderzoek," + "bron_documentdatum," + "bron_documentnummer" + ") values (?,?,?,?,?,?,?,?,?,?,?,?)"); ps.setLong(1, pand.getIdentificatie()); ps.setInt(2, pand.getAanduidingRecordInactief().ordinal()); ps.setLong(3, pand.getAanduidingRecordCorrectie()); ps.setInt(4, pand.getOfficieel().ordinal()); ps.setString(5, pand.getPandGeometrie()); ps.setInt(6, pand.getBouwjaar()); ps.setString(7, pand.getPandStatus()); ps.setTimestamp(8, new Timestamp(pand.getBegindatumTijdvakGeldigheid().getTime())); if (pand.getEinddatumTijdvakGeldigheid() == null) ps.setNull(9, Types.TIMESTAMP); else ps.setTimestamp(9, new Timestamp(pand.getEinddatumTijdvakGeldigheid().getTime())); ps.setInt(10, pand.getInOnderzoek().ordinal()); ps.setDate(11, new Date(pand.getDocumentdatum().getTime())); ps.setString(12, pand.getDocumentnummer()); return ps; } }); } catch (DataAccessException e) { throw new DAOException("Error inserting pand: " + pand.getIdentificatie(), e); } }
From source file:org.apereo.portal.security.provider.RDBMPermissionImpl.java
/** * Set the params on the PreparedStatement and execute the insert. * @param perm org.apereo.portal.security.IPermission * @param ps java.sql.PreparedStatement - the PreparedStatement for inserting a Permission row. * @exception Exception//from w ww .jav a2 s . c om */ private void primAdd(IPermission perm, PreparedStatement ps) throws Exception { java.sql.Timestamp ts = null; // NON-NULL COLUMNS: ps.clearParameters(); ps.setString(1, perm.getOwner()); ps.setInt(2, getPrincipalType(perm)); ps.setString(3, getPrincipalKey(perm)); ps.setString(4, perm.getActivity()); ps.setString(5, perm.getTarget()); // TYPE: if (perm.getType() == null) { ps.setNull(6, Types.VARCHAR); } else { ps.setString(6, perm.getType()); } // EFFECTIVE: if (perm.getEffective() == null) { ps.setNull(7, Types.TIMESTAMP); } else { ts = new java.sql.Timestamp(perm.getEffective().getTime()); ps.setTimestamp(7, ts); } // EXPIRES: if (perm.getExpires() == null) { ps.setNull(8, Types.TIMESTAMP); } else { ts = new java.sql.Timestamp(perm.getExpires().getTime()); ps.setTimestamp(8, ts); } }
From source file:com.streamsets.pipeline.lib.jdbc.multithread.TableContextUtil.java
public static String generateNextPartitionOffset(TableContext tableContext, String column, String offset) { final String partitionSize = tableContext.getOffsetColumnToPartitionOffsetAdjustments().get(column); switch (tableContext.getOffsetColumnToType().get(column)) { case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: final int int1 = Integer.parseInt(offset); final int int2 = Integer.parseInt(partitionSize); return String.valueOf(int1 + int2); case Types.TIMESTAMP: final Timestamp timestamp1 = getTimestampForOffsetValue(offset); final long timestampAdj = Long.parseLong(partitionSize); final Timestamp timestamp2 = Timestamp.from(timestamp1.toInstant().plusMillis(timestampAdj)); return getOffsetValueForTimestamp(timestamp2); case Types.BIGINT: // TIME, DATE are represented as long (epoch) case Types.TIME: case Types.DATE: final long long1 = Long.parseLong(offset); final long long2 = Long.parseLong(partitionSize); return String.valueOf(long1 + long2); case Types.FLOAT: case Types.REAL: final float float1 = Float.parseFloat(offset); final float float2 = Float.parseFloat(partitionSize); return String.valueOf(float1 + float2); case Types.DOUBLE: final double double1 = Double.parseDouble(offset); final double double2 = Double.parseDouble(partitionSize); return String.valueOf(double1 + double2); case Types.NUMERIC: case Types.DECIMAL: final BigDecimal decimal1 = new BigDecimal(offset); final BigDecimal decimal2 = new BigDecimal(partitionSize); return decimal1.add(decimal2).toString(); }//from www .ja va 2 s . c o m return null; }
From source file:gemlite.core.internal.db.AsyncEventHelper.java
/** * Set column value at given index in a prepared statement. The implementation * tries using the matching underlying type to minimize any data type * conversions, and avoid creating wrapper Java objects (e.g. {@link Integer} * for primitive int).// w ww .j ava2 s. co m * * @param type * the SQL type of the column as specified by JDBC {@link Types} * class * @param ps * the prepared statement where the column value has to be set * @param row * the source row as a {@link ResultSet} from where the value has to * be extracted * @param rowPosition * the 1-based position of the column in the provided * <code>row</code> * @param paramIndex * the 1-based position of the column in the target prepared * statement (provided <code>ps</code> argument) * @param sync * the {@link DBSynchronizer} object, if any; it is used to store * whether the current driver is JDBC4 compliant to enable performing * BLOB/CLOB operations {@link PreparedStatement#setBinaryStream}, * {@link PreparedStatement#setCharacterStream} * * @throws SQLException * in case of an exception in setting parameters */ public final void setColumnInPrepStatement(String type, Object val, PreparedStatement ps, final DBSynchronizer sync, int paramIndex) throws SQLException { switch (type) { case JavaTypes.STRING: if (val == null || StringUtils.isEmpty(val.toString())) ps.setNull(paramIndex, Types.VARCHAR); else { final String realVal = (String) val; ps.setString(paramIndex, realVal); } break; case JavaTypes.INT1: case JavaTypes.INT2: case JavaTypes.INT3: if (val == null || StringUtils.isEmpty(val.toString())) ps.setNull(paramIndex, Types.INTEGER); else { final int realVal = (int) val; ps.setInt(paramIndex, realVal); } break; case JavaTypes.DOUBLE1: case JavaTypes.DOUBLE2: if (val == null || StringUtils.isEmpty(val.toString())) ps.setNull(paramIndex, Types.DOUBLE); else { final double realVal = (double) val; ps.setDouble(paramIndex, realVal); } break; case JavaTypes.FLOAT1: case JavaTypes.FLOAT2: if (val == null || StringUtils.isEmpty(val.toString())) ps.setNull(paramIndex, Types.FLOAT); else { final float realVal = (float) val; ps.setDouble(paramIndex, realVal); } break; case JavaTypes.BOOLEAN1: case JavaTypes.BOOLEAN2: if (val == null || StringUtils.isEmpty(val.toString())) ps.setNull(paramIndex, Types.BOOLEAN); else { final boolean realVal = (boolean) val; ps.setBoolean(paramIndex, realVal); } break; case JavaTypes.DATE_SQL: if (val == null || StringUtils.isEmpty(val.toString())) ps.setNull(paramIndex, Types.DATE); else { final Date realVal = (Date) val; ps.setDate(paramIndex, realVal); } break; case JavaTypes.DATE_UTIL: if (val == null || StringUtils.isEmpty(val.toString())) ps.setNull(paramIndex, Types.DATE); else { final java.util.Date realVal = (java.util.Date) val; ps.setDate(paramIndex, new Date(realVal.getTime())); } break; case JavaTypes.BIGDECIMAL: if (val == null || StringUtils.isEmpty(val.toString())) ps.setNull(paramIndex, Types.DECIMAL); else { final BigDecimal realVal = (BigDecimal) val; ps.setBigDecimal(paramIndex, realVal); } break; case JavaTypes.TIME: if (val == null || StringUtils.isEmpty(val.toString())) ps.setNull(paramIndex, Types.TIME); else { final Time realVal = (Time) val; ps.setTime(paramIndex, realVal); } break; case JavaTypes.TIMESTAMP: if (val == null || StringUtils.isEmpty(val.toString())) ps.setNull(paramIndex, Types.TIMESTAMP); else { final Timestamp realVal = (Timestamp) val; ps.setTimestamp(paramIndex, realVal); } break; case JavaTypes.OBJECT: if (val == null || StringUtils.isEmpty(val.toString())) ps.setNull(paramIndex, Types.JAVA_OBJECT); else { final Object realVal = (Object) val; ps.setObject(paramIndex, realVal); } break; default: throw new UnsupportedOperationException("java.sql.Type = " + type + " not supported"); } }
From source file:com.nextep.designer.dbgm.services.impl.DerbyStorageService.java
@Override public int getColumnSqlType(IDataSet set, IBasicColumn c) { final DBVendor vendor = DBGMHelper.getVendorFor(set); final IDatatypeProvider datatypeProvider = DBGMHelper.getDatatypeProvider(vendor); final IDatatype type = c.getDatatype(); int jdbcType; // Analyzing type final String typeName = type.getName().toUpperCase(); if (datatypeProvider.getNumericDatatypes().contains(typeName)) { if (datatypeProvider.isDecimalDatatype(type)) { jdbcType = Types.DOUBLE; } else {/*from w w w .ja v a 2 s .co m*/ jdbcType = Types.BIGINT; } } else if (datatypeProvider.getDateDatatypes().contains(typeName)) { jdbcType = Types.TIMESTAMP; } else { jdbcType = Types.VARCHAR; } return jdbcType; }
From source file:org.jumpmind.db.platform.AbstractDatabasePlatform.java
public String[] getStringValues(BinaryEncoding encoding, Column[] metaData, Row row, boolean useVariableDates, boolean indexByPosition) { String[] values = new String[metaData.length]; Set<String> keys = row.keySet(); int i = 0;// www . j a va2 s.c o m for (String key : keys) { Column column = metaData[i]; String name = indexByPosition ? key : column.getName(); int type = column.getJdbcTypeCode(); if (row.get(name) != null) { if (type == Types.BOOLEAN || type == Types.BIT) { values[i] = row.getBoolean(name) ? "1" : "0"; } else if (column.isOfNumericType()) { values[i] = row.getString(name); } else if (!column.isTimestampWithTimezone() && (type == Types.DATE || type == Types.TIMESTAMP || type == Types.TIME)) { values[i] = getDateTimeStringValue(name, type, row, useVariableDates); } else if (column.isOfBinaryType()) { byte[] bytes = row.getBytes(name); if (encoding == BinaryEncoding.NONE) { values[i] = row.getString(name); } else if (encoding == BinaryEncoding.BASE64) { values[i] = new String(Base64.encodeBase64(bytes)); } else if (encoding == BinaryEncoding.HEX) { values[i] = new String(Hex.encodeHex(bytes)); } } else { values[i] = row.getString(name); } } i++; } return values; }
From source file:org.apache.nifi.admin.dao.impl.StandardUserDAO.java
@Override public void updateUser(NiFiUser user) throws DataAccessException { PreparedStatement statement = null; try {/*ww w . ja va 2s . c o m*/ // create a statement statement = connection.prepareStatement(UPDATE_USER); statement.setString(1, StringUtils.left(user.getIdentity(), 4096)); statement.setString(2, StringUtils.left(user.getUserName(), 4096)); statement.setString(3, StringUtils.left(user.getUserGroup(), 100)); statement.setString(6, StringUtils.left(user.getJustification(), 500)); statement.setString(7, user.getStatus().toString()); statement.setString(8, user.getId()); // set the last accessed time accordingly if (user.getLastAccessed() == null) { statement.setNull(4, Types.TIMESTAMP); } else { statement.setTimestamp(4, new java.sql.Timestamp(user.getLastAccessed().getTime())); } // set the last verified time accordingly if (user.getLastVerified() == null) { statement.setNull(5, Types.TIMESTAMP); } else { statement.setTimestamp(5, new java.sql.Timestamp(user.getLastVerified().getTime())); } // perform the update int updateCount = statement.executeUpdate(); if (updateCount != 1) { throw new DataAccessException("Unable to update user."); } } catch (SQLException sqle) { throw new DataAccessException(sqle); } catch (DataAccessException dae) { throw dae; } finally { RepositoryUtils.closeQuietly(statement); } }
From source file:org.fireflow.engine.persistence.springjdbc.PersistenceServiceSpringJdbcImpl.java
public void saveOrUpdateWorkItem(IWorkItem workitem) { String workItemId = null;/*from w w w . ja va2 s .c o m*/ if (workitem.getId() == null || workitem.getId().trim().equals("")) { StringBuffer sql = new StringBuffer(); sql.append("INSERT "); sql.append("INTO t_ff_rt_workitem "); sql.append(" ( "); sql.append(" id , "); sql.append(" state , "); sql.append(" created_time, "); sql.append(" claimed_time, "); sql.append(" end_time , "); sql.append(" actor_id , "); sql.append(" taskinstance_id, "); sql.append(" comments "); sql.append(" ) "); sql.append(" VALUES "); sql.append(" ( ?,?,?,?,? ,?,?,?)"); if (show_sql) { System.out.println("FIREWORKFLOW_JDCB:" + sql.toString()); } workItemId = java.util.UUID.randomUUID().toString().replace("-", ""); ((WorkItem) workitem).setId(workItemId); super.getJdbcTemplate().update(sql.toString(), new Object[] { workItemId, workitem.getState(), getSqlDateTime(workitem.getCreatedTime()), getSqlDateTime(workitem.getClaimedTime()), getSqlDateTime(workitem.getEndTime()), workitem.getActorId(), workitem.getTaskInstance().getId(), workitem.getComments() }, new int[] { Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR }); } else { StringBuffer sql = new StringBuffer(); sql.append("UPDATE t_ff_rt_workitem "); sql.append("SET state = ?, "); sql.append(" created_time = ?, "); sql.append(" claimed_time = ?, "); sql.append(" end_time = ?, "); sql.append(" actor_id = ?, "); sql.append(" taskinstance_id = ?, "); sql.append(" comments = ? "); sql.append("WHERE ID = ? "); if (show_sql) { System.out.println("FIREWORKFLOW_JDCB:" + sql.toString()); } super.getJdbcTemplate().update(sql.toString(), new Object[] { workitem.getState(), getSqlDateTime(workitem.getCreatedTime()), getSqlDateTime(workitem.getClaimedTime()), getSqlDateTime(workitem.getEndTime()), workitem.getActorId(), workitem.getTaskInstance().getId(), workitem.getComments(), workitem.getId() }, new int[] { Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR }); } }
From source file:org.exist.xquery.modules.sql.ExecuteFunction.java
private void setParametersOnPreparedStatement(Statement stmt, Element parametersElement) throws SQLException, XPathException { if (parametersElement.getNamespaceURI().equals(SQLModule.NAMESPACE_URI) && parametersElement.getLocalName().equals(PARAMETERS_ELEMENT_NAME)) { NodeList paramElements = parametersElement.getElementsByTagNameNS(SQLModule.NAMESPACE_URI, PARAM_ELEMENT_NAME);//from ww w. jav a 2s . com for (int i = 0; i < paramElements.getLength(); i++) { Element param = ((Element) paramElements.item(i)); Node child = param.getFirstChild(); // Prevent NPE if (child != null) { if (child instanceof ReferenceNode) { child = ((ReferenceNode) child).getReference().getNode(); } final String value = child.getNodeValue(); final String type = param.getAttributeNS(SQLModule.NAMESPACE_URI, TYPE_ATTRIBUTE_NAME); final int sqlType = SQLUtils.sqlTypeFromString(type); if (sqlType == Types.TIMESTAMP) { final DateTimeValue dv = new DateTimeValue(value); final Timestamp timestampValue = new Timestamp(dv.getDate().getTime()); ((PreparedStatement) stmt).setTimestamp(i + 1, timestampValue); } else { ((PreparedStatement) stmt).setObject(i + 1, value, sqlType); } } } } }
From source file:com.netspective.axiom.sql.StoredProcedureParameter.java
/** * Extract the OUT parameter values from the callable statment and * assign them to the value of the parameter. *///w w w . j a v a 2 s . c om public void extract(ConnectionContext cc, CallableStatement stmt) throws SQLException { if (getType().getValueIndex() == StoredProcedureParameter.Type.IN) return; int index = this.getIndex(); QueryParameterType paramType = getSqlType(); int jdbcType = paramType.getJdbcType(); String identifier = paramType.getIdentifier(); // result sets are special if (identifier.equals(QueryParameterType.RESULTSET_IDENTIFIER)) { ResultSet rs = (ResultSet) stmt.getObject(index); QueryResultSet qrs = new QueryResultSet(getParent().getProcedure(), cc, rs); value.getValue(cc).setValue(qrs); return; } switch (jdbcType) { case Types.VARCHAR: value.getValue(cc).setTextValue(stmt.getString(index)); break; case Types.INTEGER: value.getValue(cc).setValue(new Integer(stmt.getInt(index))); break; case Types.DOUBLE: value.getValue(cc).setValue(new Double(stmt.getDouble(index))); break; case Types.CLOB: Clob clob = stmt.getClob(index); value.getValue(cc).setTextValue(clob.getSubString(1, (int) clob.length())); break; case java.sql.Types.ARRAY: Array array = stmt.getArray(index); value.getValue(cc).setValue(array); break; case java.sql.Types.BIGINT: long bigint = stmt.getLong(index); value.getValue(cc).setValue(new Long(bigint)); break; case java.sql.Types.BINARY: value.getValue(cc).setTextValue(new String(stmt.getBytes(index))); break; case java.sql.Types.BIT: boolean bit = stmt.getBoolean(index); value.getValue(cc).setValue(new Boolean(bit)); case java.sql.Types.BLOB: value.getValue(cc).setValue(stmt.getBlob(index)); break; case java.sql.Types.CHAR: value.getValue(cc).setTextValue(stmt.getString(index)); break; case java.sql.Types.DATE: value.getValue(cc).setValue(stmt.getDate(index)); break; case java.sql.Types.DECIMAL: value.getValue(cc).setValue(stmt.getBigDecimal(index)); break; case java.sql.Types.DISTINCT: value.getValue(cc).setValue(stmt.getObject(index)); break; case java.sql.Types.FLOAT: value.getValue(cc).setValue(new Float(stmt.getFloat(index))); break; case java.sql.Types.JAVA_OBJECT: value.getValue(cc).setValue(stmt.getObject(index)); break; case java.sql.Types.LONGVARBINARY: value.getValue(cc).setTextValue(new String(stmt.getBytes(index))); break; case java.sql.Types.LONGVARCHAR: value.getValue(cc).setTextValue(stmt.getString(index)); break; //case java.sql.Types.NULL: // value.getValue(cc).setValue(null); // break; case java.sql.Types.NUMERIC: value.getValue(cc).setValue(stmt.getBigDecimal(index)); break; case java.sql.Types.OTHER: value.getValue(cc).setValue(stmt.getObject(index)); break; case java.sql.Types.REAL: value.getValue(cc).setValue(new Float(stmt.getFloat(index))); break; //case java.sql.Types.REF: // Ref ref = stmt.getRef(index); // break; case java.sql.Types.SMALLINT: short sh = stmt.getShort(index); value.getValue(cc).setValue(new Short(sh)); break; case java.sql.Types.STRUCT: value.getValue(cc).setValue(stmt.getObject(index)); break; case java.sql.Types.TIME: value.getValue(cc).setValue(stmt.getTime(index)); break; case java.sql.Types.TIMESTAMP: value.getValue(cc).setValue(stmt.getTimestamp(index)); break; case java.sql.Types.TINYINT: byte b = stmt.getByte(index); value.getValue(cc).setValue(new Byte(b)); break; case java.sql.Types.VARBINARY: value.getValue(cc).setValue(stmt.getBytes(index)); break; default: throw new RuntimeException( "Unknown JDBC Type set for stored procedure parameter '" + this.getName() + "'."); } }