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.openddal.test.BaseTestCase.java
/** * Check if the result set meta data is correct. * * @param rs the result set/*from ww w .j a v a 2 s . co m*/ * @param columnCount the expected column count * @param labels the expected column labels * @param datatypes the expected data types * @param precision the expected precisions * @param scale the expected scales */ protected void assertResultSetMeta(ResultSet rs, int columnCount, String[] labels, int[] datatypes, int[] precision, int[] scale) throws SQLException { ResultSetMetaData meta = rs.getMetaData(); int cc = meta.getColumnCount(); if (cc != columnCount) { fail("result set contains " + cc + " columns not " + columnCount); } for (int i = 0; i < columnCount; i++) { if (labels != null) { String l = meta.getColumnLabel(i + 1); if (!labels[i].equals(l)) { fail("column label " + i + " is " + l + " not " + labels[i]); } } if (datatypes != null) { int t = meta.getColumnType(i + 1); if (datatypes[i] != t) { fail("column datatype " + i + " is " + t + " not " + datatypes[i] + " (prec=" + meta.getPrecision(i + 1) + " scale=" + meta.getScale(i + 1) + ")"); } String typeName = meta.getColumnTypeName(i + 1); String className = meta.getColumnClassName(i + 1); switch (t) { case Types.INTEGER: Assert.assertEquals("INTEGER", typeName); Assert.assertEquals("java.lang.Integer", className); break; case Types.VARCHAR: Assert.assertEquals("VARCHAR", typeName); Assert.assertEquals("java.lang.String", className); break; case Types.SMALLINT: Assert.assertEquals("SMALLINT", typeName); Assert.assertEquals("java.lang.Short", className); break; case Types.TIMESTAMP: Assert.assertEquals("TIMESTAMP", typeName); Assert.assertEquals("java.sql.Timestamp", className); break; case Types.DECIMAL: Assert.assertEquals("DECIMAL", typeName); Assert.assertEquals("java.math.BigDecimal", className); break; default: } } if (precision != null) { int p = meta.getPrecision(i + 1); if (precision[i] != p) { fail("column precision " + i + " is " + p + " not " + precision[i]); } } if (scale != null) { int s = meta.getScale(i + 1); if (scale[i] != s) { fail("column scale " + i + " is " + s + " not " + scale[i]); } } } }
From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java
@Override public void insert(final Ligplaats ligplaats) throws DAOException { try {/*w ww . j a v a2 s . c om*/ transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection .prepareStatement("insert into bag_ligplaats (" + "bag_ligplaats_id," + "aanduiding_record_inactief," + "aanduiding_record_correctie," + "officieel," + "ligplaats_status," + "ligplaats_geometrie," + "begindatum_tijdvak_geldigheid," + "einddatum_tijdvak_geldigheid," + "in_onderzoek," + "bron_documentdatum," + "bron_documentnummer," + "bag_nummeraanduiding_id" + ") values (?,?,?,?,?,?,?,?,?,?,?,?)"); ps.setLong(1, ligplaats.getIdentificatie()); ps.setInt(2, ligplaats.getAanduidingRecordInactief().ordinal()); ps.setLong(3, ligplaats.getAanduidingRecordCorrectie()); ps.setInt(4, ligplaats.getOfficieel().ordinal()); ps.setInt(5, ligplaats.getLigplaatsStatus().ordinal()); ps.setString(6, ligplaats.getLigplaatsGeometrie()); ps.setTimestamp(7, new Timestamp(ligplaats.getBegindatumTijdvakGeldigheid().getTime())); if (ligplaats.getEinddatumTijdvakGeldigheid() == null) ps.setNull(8, Types.TIMESTAMP); else ps.setTimestamp(8, new Timestamp(ligplaats.getEinddatumTijdvakGeldigheid().getTime())); ps.setInt(9, ligplaats.getInOnderzoek().ordinal()); ps.setDate(10, new Date(ligplaats.getDocumentdatum().getTime())); ps.setString(11, ligplaats.getDocumentnummer()); ps.setLong(12, ligplaats.getHoofdAdres()); return ps; } }); insertNevenadressen(TypeAdresseerbaarObject.LIGPLAATS, ligplaats); } }); } catch (DataAccessException e) { throw new DAOException("Error inserting ligplaats: " + ligplaats.getIdentificatie(), e); } }
From source file:org.siphon.jssql.SqlExecutor.java
private String translateTypeName(int columnType, String columnTypeName) { switch (columnType) { case Types.VARCHAR: case Types.CHAR: case Types.NCHAR: case Types.NVARCHAR: case Types.LONGVARCHAR: case Types.LONGNVARCHAR: return "STRING"; case Types.INTEGER: case Types.SMALLINT: return "INT"; case Types.BIGINT: return "LONG"; case Types.FLOAT: return "FLOAT"; case Types.REAL: case Types.DOUBLE: return "DOUBLE"; case Types.NUMERIC: case Types.DECIMAL: return "DECIMAL"; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: case Types.TIME_WITH_TIMEZONE: return "DATE"; case Types.ROWID: return "ROWID"; case Types.BLOB: return "BINARY"; // return "BLOB"; case Types.CLOB: return "STRING"; // return "CLOB"; case Types.VARBINARY: case Types.LONGVARBINARY: return "BINARY"; case Types.BOOLEAN: return "BOOLEAN"; case Types.ARRAY: return "ARRAY"; case Types.OTHER: return columnTypeName.toUpperCase(); default://from ww w . j av a 2 s . c om return "UNKNOWN"; } }
From source file:org.wso2.carbon.dataservices.core.odata.RDBMSDataHandler.java
/** * This method bind values to prepared statement. * * @param type data Type/*from w ww. j av a 2 s. com*/ * @param value String value * @param ordinalPosition Ordinal Position * @param sqlStatement Statement * @throws SQLException * @throws ParseException * @throws ODataServiceFault */ private void bindValuesToPreparedStatement(int type, String value, int ordinalPosition, PreparedStatement sqlStatement) throws SQLException, ParseException, ODataServiceFault { byte[] data; try { switch (type) { case Types.INTEGER: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setInt(ordinalPosition, ConverterUtil.convertToInt(value)); } break; case Types.TINYINT: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setByte(ordinalPosition, ConverterUtil.convertToByte(value)); } break; case Types.SMALLINT: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setShort(ordinalPosition, ConverterUtil.convertToShort(value)); } break; case Types.DOUBLE: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setDouble(ordinalPosition, ConverterUtil.convertToDouble(value)); } break; case Types.VARCHAR: /* fall through */ case Types.CHAR: /* fall through */ case Types.LONGVARCHAR: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setString(ordinalPosition, value); } break; case Types.CLOB: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setClob(ordinalPosition, new BufferedReader(new StringReader(value)), value.length()); } break; case Types.BOOLEAN: /* fall through */ case Types.BIT: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setBoolean(ordinalPosition, ConverterUtil.convertToBoolean(value)); } break; case Types.BLOB: /* fall through */ case Types.LONGVARBINARY: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { data = this.getBytesFromBase64String(value); sqlStatement.setBlob(ordinalPosition, new ByteArrayInputStream(data), data.length); } break; case Types.BINARY: /* fall through */ case Types.VARBINARY: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { data = this.getBytesFromBase64String(value); sqlStatement.setBinaryStream(ordinalPosition, new ByteArrayInputStream(data), data.length); } break; case Types.DATE: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setDate(ordinalPosition, DBUtils.getDate(value)); } break; case Types.DECIMAL: /* fall through */ case Types.NUMERIC: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setBigDecimal(ordinalPosition, ConverterUtil.convertToBigDecimal(value)); } break; case Types.FLOAT: /* fall through */ case Types.REAL: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setFloat(ordinalPosition, ConverterUtil.convertToFloat(value)); } break; case Types.TIME: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setTime(ordinalPosition, DBUtils.getTime(value)); } break; case Types.LONGNVARCHAR: /* fall through */ case Types.NCHAR: /* fall through */ case Types.NVARCHAR: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setNString(ordinalPosition, value); } break; case Types.NCLOB: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setNClob(ordinalPosition, new BufferedReader(new StringReader(value)), value.length()); } break; case Types.BIGINT: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setLong(ordinalPosition, ConverterUtil.convertToLong(value)); } break; case Types.TIMESTAMP: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setTimestamp(ordinalPosition, DBUtils.getTimestamp(value)); } break; default: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setString(ordinalPosition, value); } break; } } catch (DataServiceFault e) { throw new ODataServiceFault(e, "Error occurred while binding values. :" + e.getMessage()); } }
From source file:com.splicemachine.derby.utils.SpliceAdmin.java
/** * Prints all the information related to the execution plans of the stored prepared statements (metadata queries). *///from ww w.j a v a 2 s. c om public static void SYSCS_GET_STORED_STATEMENT_PLAN_INFO(ResultSet[] rs) throws SQLException { try { // Wow... who knew it was so much work to create a ResultSet? Ouch! The following code is annoying. LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC(); DataDictionary dd = lcc.getDataDictionary(); List list = dd.getAllSPSDescriptors(); ArrayList<ExecRow> rows = new ArrayList<>(list.size()); // Describe the format of the input rows (ExecRow). // // Columns of "virtual" row: // STMTNAME VARCHAR // TYPE CHAR // VALID BOOLEAN // LASTCOMPILED TIMESTAMP // INITIALLY_COMPILABLE BOOLEAN // CONSTANTSTATE BLOB --> VARCHAR showing existence of plan DataValueDescriptor[] dvds = new DataValueDescriptor[] { new SQLVarchar(), new SQLChar(), new SQLBoolean(), new SQLTimestamp(), new SQLBoolean(), new SQLVarchar() }; int numCols = dvds.length; ExecRow dataTemplate = new ValueRow(numCols); dataTemplate.setRowArray(dvds); // Transform the descriptors into the rows. for (Object aList : list) { SPSDescriptor spsd = (SPSDescriptor) aList; ExecPreparedStatement ps = spsd.getPreparedStatement(false); dvds[0].setValue(spsd.getName()); dvds[1].setValue(spsd.getTypeAsString()); dvds[2].setValue(spsd.isValid()); dvds[3].setValue(spsd.getCompileTime()); dvds[4].setValue(spsd.initiallyCompilable()); dvds[5].setValue(spsd.getPreparedStatement(false) == null ? null : "[object]"); rows.add(dataTemplate.getClone()); } // Describe the format of the output rows (ResultSet). ResultColumnDescriptor[] columnInfo = new ResultColumnDescriptor[numCols]; columnInfo[0] = new GenericColumnDescriptor("STMTNAME", DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 60)); columnInfo[1] = new GenericColumnDescriptor("TYPE", DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.CHAR, 4)); columnInfo[2] = new GenericColumnDescriptor("VALID", DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.BOOLEAN)); columnInfo[3] = new GenericColumnDescriptor("LASTCOMPILED", DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.TIMESTAMP)); columnInfo[4] = new GenericColumnDescriptor("INITIALLY_COMPILABLE", DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.BOOLEAN)); columnInfo[5] = new GenericColumnDescriptor("CONSTANTSTATE", DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, 13)); EmbedConnection defaultConn = (EmbedConnection) getDefaultConn(); Activation lastActivation = defaultConn.getLanguageConnection().getLastActivation(); IteratorNoPutResultSet resultsToWrap = new IteratorNoPutResultSet(rows, columnInfo, lastActivation); resultsToWrap.openCore(); EmbedResultSet ers = new EmbedResultSet40(defaultConn, resultsToWrap, false, null, true); rs[0] = ers; } catch (StandardException se) { throw PublicAPI.wrapStandardException(se); } }
From source file:org.pentaho.di.jdbc.Support.java
/** * Get a String describing the supplied JDBC type constant. * * @param jdbcType The constant to be decoded. * @return The text decode of the type constant as a <code>String</code>. *//*from w ww .j a v a 2s . c om*/ static String getJdbcTypeName(int jdbcType) { switch (jdbcType) { case java.sql.Types.ARRAY: return "ARRAY"; case java.sql.Types.BIGINT: return "BIGINT"; case java.sql.Types.BINARY: return "BINARY"; case java.sql.Types.BIT: return "BIT"; case java.sql.Types.BLOB: return "BLOB"; case java.sql.Types.BOOLEAN: return "BOOLEAN"; case java.sql.Types.CHAR: return "CHAR"; case java.sql.Types.CLOB: return "CLOB"; // case JtdsStatement.DATALINK: return "DATALINK"; case java.sql.Types.DATE: return "DATE"; case java.sql.Types.DECIMAL: return "DECIMAL"; case java.sql.Types.DISTINCT: return "DISTINCT"; case java.sql.Types.DOUBLE: return "DOUBLE"; case java.sql.Types.FLOAT: return "FLOAT"; case java.sql.Types.INTEGER: return "INTEGER"; case java.sql.Types.JAVA_OBJECT: return "JAVA_OBJECT"; case java.sql.Types.LONGVARBINARY: return "LONGVARBINARY"; case java.sql.Types.LONGVARCHAR: return "LONGVARCHAR"; case java.sql.Types.NULL: return "NULL"; case java.sql.Types.NUMERIC: return "NUMERIC"; case java.sql.Types.OTHER: return "OTHER"; case java.sql.Types.REAL: return "REAL"; case java.sql.Types.REF: return "REF"; case java.sql.Types.SMALLINT: return "SMALLINT"; case java.sql.Types.STRUCT: return "STRUCT"; case java.sql.Types.TIME: return "TIME"; case java.sql.Types.TIMESTAMP: return "TIMESTAMP"; case java.sql.Types.TINYINT: return "TINYINT"; case java.sql.Types.VARBINARY: return "VARBINARY"; case java.sql.Types.VARCHAR: return "VARCHAR"; default: return "ERROR"; } }
From source file:org.nuclos.server.dblayer.impl.standard.StandardSqlDBAccess.java
protected static DbGenericType getDbGenericType(int sqlType, String typeName) { switch (sqlType) { case Types.VARCHAR: case Types.NVARCHAR: case Types.NCHAR: case Types.CHAR: return DbGenericType.VARCHAR; case Types.NUMERIC: case Types.DECIMAL: return DbGenericType.NUMERIC; case Types.BIT: case Types.BOOLEAN: return DbGenericType.BOOLEAN; case Types.DATE: return DbGenericType.DATE; case Types.BLOB: case Types.VARBINARY: case Types.BINARY: case Types.LONGVARBINARY: return DbGenericType.BLOB; case Types.CLOB: case Types.LONGVARCHAR: return DbGenericType.CLOB; case Types.TIMESTAMP: return DbGenericType.DATETIME; default:/*from w w w . j a v a 2 s .c o m*/ return null; } }
From source file:net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.java
protected void setTimestamp(int parameterIndex, Object parameterValue, JRPropertiesHolder properties) throws SQLException { if (parameterValue == null) { statement.setNull(parameterIndex, Types.TIMESTAMP); } else {/*from w ww .jav a 2 s . c o m*/ Calendar cal = getParameterCalendar(properties); if (log.isDebugEnabled()) { log.debug("setting timestamp parameter " + parameterIndex + " as " + parameterValue + " (" + ((java.sql.Timestamp) parameterValue).getTime() + ")" + " with calendar " + cal); } if (cal == null) { statement.setTimestamp(parameterIndex, (java.sql.Timestamp) parameterValue); } else { statement.setTimestamp(parameterIndex, (java.sql.Timestamp) parameterValue, cal); } } }
From source file:org.gbif.harvest.portal.synchronise.dao.jdbc.RawOccurrenceRecordDaoImpl.java
/** * @see org.gbif.harvest.portal.synchronise.dao.RawOccurrenceRecordDao#getCreatedOrModifiedSince(long, java.util.Date, long, int) *//* w w w . j ava 2 s . c om*/ @SuppressWarnings("unchecked") public List<RawOccurrenceRecord> getCreatedOrModifiedSince(final long dataResourceId, final java.util.Date start, long startAt, int maxResults) { log.info("Getting records last harvested since[" + start + "] for DR ID:" + dataResourceId); final Timestamp ts = new Timestamp(start.getTime()); List<RawOccurrenceRecord> results = (List<RawOccurrenceRecord>) getJdbcTemplate().query( RawOccurrenceRecordDaoImpl.QUERY_MODIFIED_SINCE, new Object[] { dataResourceId, ts, startAt, maxResults }, new int[] { Types.INTEGER, Types.TIMESTAMP, Types.INTEGER, Types.INTEGER }, new RowMapperResultSetExtractor(rawOccurrenceRecordRowMapper)); return results; }
From source file:org.siphon.jssql.SqlExecutor.java
private Object fieldValueToNativeObject(int columnType, ResultSet rs, String columnName) throws SQLException, SqlExecutorException, ScriptException { // System.out.println("get column " + columnName + " type " + // columnType); // longraw ? getObject() ??? byte[], // ojdbc6 ? longraw? BLOB // LONGRAW getObject ? LongRaw?? // BLOB ??? LONGRAWBinary? // LongRaw BLOB ? t.longraw, t.blob , t.blob, // t.longraw // if (columnName.equals("datefld")) { // System.out.println(); // }/*from w w w.j av a 2s . c o m*/ Object obj = rs.getObject(columnName); if (obj == null) { return null; } else { switch (columnType) { case Types.DATE: obj = rs.getDate(columnName); break; case Types.TIME: obj = rs.getTime(columnName); break; case Types.TIMESTAMP: obj = rs.getTimestamp(columnName); break; case Types.TIMESTAMP_WITH_TIMEZONE: obj = rs.getTimestamp(columnName); break; // PG TIMESTAMP WITH TIMEZONE ?? // ? JDBC ????? // ? joda ?? jdbc ?? } } return jdbcReturnTypeToJsObject(obj); }