List of usage examples for java.sql Types DATE
int DATE
To view the source code for java.sql Types DATE.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DATE
.
From source file:com.squid.core.jdbc.vendor.sqlserver.SQLServerJDBCDataFormatter.java
@Override public void setData(PreparedStatement pstmt, int position, Object data, int colType, int size, int precision) throws SQLException, NullPointerException { // TODO Auto-generated method stub if (colType == Types.DATE || colType == Types.TIMESTAMP || colType == Types.TIME) { if (data != null) { pstmt.setDate(position, new java.sql.Date(((java.util.Date) data).getTime())); } else {// w ww. java 2 s . c o m pstmt.setDate(position, null); } } else { super.setData(pstmt, position, data, colType, size, precision); } }
From source file:com.streamsets.pipeline.stage.it.AvroToParquetHiveIT.java
@Parameterized.Parameters(name = "type({0})") public static Collection<Object[]> data() throws Exception { return Arrays.asList(new Object[][] { // Primitive types { "\"boolean\"", true, true, "BOOLEAN", Types.BOOLEAN, "0" }, { "\"int\"", Integer.MIN_VALUE, Integer.MIN_VALUE, "INT", Types.INTEGER, "0" }, { "\"long\"", Long.MAX_VALUE, Long.MAX_VALUE, "BIGINT", Types.BIGINT, "0" }, // From some reason type is FLOAT, but returned object is double { "\"float\"", Float.NaN, Double.NaN, "FLOAT", Types.FLOAT, "0" }, { "\"double\"", Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, "DOUBLE", Types.DOUBLE, "0" }, { "\"bytes\"", ByteBuffer.wrap(new byte[] { (byte) 0x00, (byte) 0xFF }), new byte[] { (byte) 0x00, (byte) 0xFF }, "BINARY", Types.BINARY, "1.0" }, { "\"string\"", new Utf8("StreamSets"), "StreamSets", "STRING", Types.VARCHAR, "1.0" }, // Complex types are skipped for now // Logical types { DECIMAL.toString(), ByteBuffer.wrap(new byte[] { (byte) 0x0F }), new BigDecimal("2"), "DECIMAL", Types.DECIMAL, "0" }, { DATE.toString(), 17039, new java.sql.Date(116, 7, 26), "DATE", Types.DATE, "1.2" }, }); }
From source file:wzw.sql.ResultSetConverter.java
/** * ?/* w ww .j a v a 2 s. co m*/ * @param rs * @param type Listjava.sql.Types * @return * @throws SQLException */ public static Object toType(ResultSet rs, int type) throws SQLException { if (rs.next()) { // run rs.next() switch (type) { case Types.INTEGER: return new Integer(rs.getInt(1)); case Types.BIGINT: return new Long(rs.getLong(1)); case Types.VARCHAR: return rs.getString(1); case Types.FLOAT: return new Float(rs.getFloat(1)); case Types.DECIMAL: case Types.DOUBLE: case Types.NUMERIC: return new Double(rs.getDouble(1)); case Types.TIMESTAMP: return rs.getTimestamp(1); case Types.DATE: return rs.getDate(1); case Types.TIME: return rs.getTime(1); default: return null; } } return null; }
From source file:org.apache.kylin.jdbc.KylinClient.java
@SuppressWarnings("rawtypes") public static Class convertType(int sqlType) { Class result = Object.class; switch (sqlType) { case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: result = String.class; break;/*www.j av a2s .c o m*/ case Types.NUMERIC: case Types.DECIMAL: result = BigDecimal.class; break; case Types.BIT: result = Boolean.class; break; case Types.TINYINT: result = Byte.class; break; case Types.SMALLINT: result = Short.class; break; case Types.INTEGER: result = Integer.class; break; case Types.BIGINT: result = Long.class; break; case Types.REAL: case Types.FLOAT: case Types.DOUBLE: result = Double.class; break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: result = Byte[].class; break; case Types.DATE: result = Date.class; break; case Types.TIME: result = Time.class; break; case Types.TIMESTAMP: result = Timestamp.class; break; default: //do nothing break; } return result; }
From source file:com.tesora.dve.common.TestDataGenerator.java
protected Object getColumnValue(ColumnMetadata cm) { Object cv = null;/*from w w w. j a va 2s. c om*/ Calendar cal = Calendar.getInstance(); switch (cm.getDataType()) { case Types.BIT: case Types.BOOLEAN: cv = Boolean.TRUE; break; case Types.BIGINT: cv = Long.MAX_VALUE; break; case Types.CHAR: case Types.VARCHAR: cv = StringUtils.left(baseString, cm.getSize()); break; case Types.SMALLINT: cv = Short.MAX_VALUE; break; case Types.TINYINT: cv = Byte.MAX_VALUE; break; case Types.INTEGER: cv = Integer.MAX_VALUE; break; case Types.DOUBLE: cv = new Double(1234.5678); // TODO need to handle s,p break; case Types.FLOAT: cv = new Float(123.56); // TODO need to handle s,p break; case Types.DECIMAL: cv = new BigDecimal("12345.6789"); // TODO need to handle s,p break; case Types.DATE: cal.setTimeInMillis(123456789); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); cv = cal.getTime(); break; case Types.TIMESTAMP: cal.setTimeInMillis(123456789); cv = cal.getTime(); break; case Types.TIME: cv = new Time(123456789); break; default: break; } return cv; }
From source file:cherry.foundation.type.querydsl.LocalDateTypeTest.java
@Test public void testMisc() { LocalDateType type = new LocalDateType(Types.DATE); assertEquals(1, type.getSQLTypes().length); assertEquals(Types.DATE, type.getSQLTypes()[0]); assertEquals("2015-01-23", type.getLiteral(new LocalDate(2015, 1, 23))); }
From source file:com.jk.framework.dao.dynamic.meta.Field.java
/** * Gets the value as double./*from w w w. ja v a2 s . co m*/ * * @param defaultValue * the default value * @return the value as double */ public double getValueAsDouble(final float defaultValue) { if (getValue() == null || getValue().trim().equals("")) { return defaultValue; } if (getMeta().getType() == Types.DATE || getMeta().getType() == Types.TIME) { final Date date = (Date) getValueObject(); return date.getTime(); } return Double.parseDouble(getValue()); }
From source file:org.jumpmind.db.platform.sqlite.SqliteJdbcSqlTemplate.java
@Override public void setValues(PreparedStatement ps, Object[] args, int[] argTypes, LobHandler lobHandler) throws SQLException { for (int i = 1; i <= args.length; i++) { Object arg = args[i - 1]; int argType = argTypes != null && argTypes.length >= i ? argTypes[i - 1] : SqlTypeValue.TYPE_UNKNOWN; if (argType == Types.BLOB && lobHandler != null && arg instanceof byte[]) { lobHandler.getLobCreator().setBlobAsBytes(ps, i, (byte[]) arg); } else if (argType == Types.BLOB && lobHandler != null && arg instanceof String) { lobHandler.getLobCreator().setBlobAsBytes(ps, i, arg.toString().getBytes()); } else if (argType == Types.CLOB && lobHandler != null) { lobHandler.getLobCreator().setClobAsString(ps, i, (String) arg); } else if (arg != null && argType == Types.DATE && arg instanceof Date) { Date clone = (Date) (((Date) arg).clone()); arg = FormatUtils.TIMESTAMP_FORMATTER.format(DateUtils.truncate(clone, Calendar.DATE)); args[i - 1] = arg;//from ww w . j a v a 2 s . c o m StatementCreatorUtils.setParameterValue(ps, i, verifyArgType(arg, argType), arg); } else if (arg != null && (arg instanceof Date || arg instanceof Timestamp)) { arg = FormatUtils.TIMESTAMP_FORMATTER.format(arg); args[i - 1] = arg; StatementCreatorUtils.setParameterValue(ps, i, verifyArgType(arg, argType), arg); } else { if (arg instanceof BigDecimal) { arg = ((BigDecimal) arg).doubleValue(); args[i - 1] = arg; } StatementCreatorUtils.setParameterValue(ps, i, verifyArgType(arg, argType), arg); } } }
From source file:org.apache.openjpa.jdbc.schema.Schemas.java
/** * Return the {@link Types} constant for the given SQL type name. *//*from ww w . jav a 2 s . c om*/ public static int getJDBCType(String name) { if ("array".equalsIgnoreCase(name)) return Types.ARRAY; if ("bigint".equalsIgnoreCase(name)) return Types.BIGINT; if ("binary".equalsIgnoreCase(name)) return Types.BINARY; if ("bit".equalsIgnoreCase(name)) return Types.BIT; if ("blob".equalsIgnoreCase(name)) return Types.BLOB; if ("char".equalsIgnoreCase(name)) return Types.CHAR; if ("clob".equalsIgnoreCase(name)) return Types.CLOB; if ("date".equalsIgnoreCase(name)) return Types.DATE; if ("decimal".equalsIgnoreCase(name)) return Types.DECIMAL; if ("distinct".equalsIgnoreCase(name)) return Types.DISTINCT; if ("double".equalsIgnoreCase(name)) return Types.DOUBLE; if ("float".equalsIgnoreCase(name)) return Types.FLOAT; if ("integer".equalsIgnoreCase(name)) return Types.INTEGER; if ("java_object".equalsIgnoreCase(name)) return Types.JAVA_OBJECT; if ("longvarbinary".equalsIgnoreCase(name)) return Types.LONGVARBINARY; if ("longvarchar".equalsIgnoreCase(name)) return Types.LONGVARCHAR; if ("null".equalsIgnoreCase(name)) return Types.NULL; if ("numeric".equalsIgnoreCase(name)) return Types.NUMERIC; if ("other".equalsIgnoreCase(name)) return Types.OTHER; if ("real".equalsIgnoreCase(name)) return Types.REAL; if ("ref".equalsIgnoreCase(name)) return Types.REF; if ("smallint".equalsIgnoreCase(name)) return Types.SMALLINT; if ("struct".equalsIgnoreCase(name)) return Types.STRUCT; if ("time".equalsIgnoreCase(name)) return Types.TIME; if ("timestamp".equalsIgnoreCase(name)) return Types.TIMESTAMP; if ("tinyint".equalsIgnoreCase(name)) return Types.TINYINT; if ("varbinary".equalsIgnoreCase(name)) return Types.VARBINARY; if ("varchar".equalsIgnoreCase(name)) return Types.VARCHAR; if (name == null || name.toLowerCase().startsWith("unknown")) return Types.OTHER; throw new IllegalArgumentException("name = " + name); }
From source file:gov.nih.nci.cabig.caaers.datamigrator.CaaersDataMigratorTemplate.java
@Transactional public final void migrateData() { Integer statusCode = 0;/* www . j a v a 2 s . c o m*/ //check the status_code String query = "SELECT STATUS_CODE, RUNDATE FROM caaers_bootstrap_log WHERE OPERATION_CODE = " + migratorId(); List<Map<String, Object>> l = getJdbcTemplate().queryForList(query); boolean noDataFound = CollectionUtils.isEmpty(l); CaaersDataMigrationContext context = new CaaersDataMigrationContext(isOralceDB(), isPostgresDB()); if (!noDataFound) { Map map = l.get(0); statusCode = ((Number) map.get("STATUS_CODE")).intValue(); String ranDate = String.valueOf(map.get("RUNDATE")); //arleady ran this migration sucessfully ? if (statusCodeComplete.equals(statusCode)) { log.info(String.format("Skipping the processing as the migrator[%s] already ran on %s.", new Object[] { getClass().getName(), ranDate })); return; } } //do the template steps try { beforeMigrate(context); migrate(context); afterMigrate(context); statusCode = statusCodeComplete; //update the bootstrap if (noDataFound) { getJdbcTemplate().update( "insert into caaers_bootstrap_log(id, operation_code, status_code, rundate) values(?,?,?, ?)", new Object[] { migratorId(), migratorId(), statusCode, new Date() }, new int[] { Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.DATE }); } else { getJdbcTemplate().update( "update caaers_bootstrap_log set status_code = ? , rundate = ? where operation_code = ?", new Object[] { statusCode, new Date(), migratorId() }, new int[] { Types.INTEGER, Types.DATE, Types.INTEGER }); } } catch (Exception e) { log.error(String.format("Error while running the migrator %s", getClass().getName()), e); } }