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:org.akaza.openclinica.dao.managestudy.StudySubjectDAO.java
/** * Create a study subject (that is, enroll a subject in a study). * * @param sb/*w w w . ja va 2s . co m*/ * The study subject to create. * @param withGroup * <code>true</code> if the group id has been set (primarily * for use with genetic studies); <code>false</false> otherwise. * @return The study subject with id set to the insert id if the operation * was successful, or 0 otherwise. */ public StudySubjectBean create(StudySubjectBean sb, boolean withGroup) { HashMap variables = new HashMap(); HashMap nullVars = new HashMap(); int ind = 1; variables.put(new Integer(ind), sb.getLabel()); ind++; variables.put(new Integer(ind), new Integer(sb.getSubjectId())); ind++; variables.put(new Integer(ind), new Integer(sb.getStudyId())); ind++; variables.put(new Integer(ind), new Integer(sb.getStatus().getId())); ind++; // Date_created is now() variables.put(new Integer(ind), new Integer(sb.getOwner().getId())); ind++; // if (withGroup) { // variables.put(new Integer(ind), new Integer(sb.getStudyGroupId())); // ind++; // } else { // nullVars.put(new Integer(ind), new Integer(TypeNames.INT)); // variables.put(new Integer(ind), null); // ind++; // } Date enrollmentDate = sb.getEnrollmentDate(); if (enrollmentDate == null) { nullVars.put(new Integer(ind), new Integer(Types.DATE)); variables.put(new Integer(ind), null); ind++; } else { variables.put(new Integer(ind), enrollmentDate); ind++; } variables.put(new Integer(ind), sb.getSecondaryLabel()); ind++; variables.put(new Integer(ind), getValidOid(sb)); ind++; this.executeWithPK(digester.getQuery("create"), variables, nullVars); if (isQuerySuccessful()) { sb.setId(getLatestPK()); } SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(ds); ArrayList groupMaps = sb.getStudyGroupMaps(); for (int i = 0; i < groupMaps.size(); i++) { SubjectGroupMapBean sgmb = (SubjectGroupMapBean) groupMaps.get(i); sgmb = (SubjectGroupMapBean) sgmdao.create(sgmb); if (sgmdao.isQuerySuccessful()) { sgmb.setId(sgmdao.getCurrentPK()); } } return sb; }
From source file:org.executequery.gui.resultset.ResultSetTableModel.java
public Class<?> getColumnClass(int column) { if (tableData.isEmpty()) { return String.class; }//w ww .j a va 2 s. c o m RecordDataItem recordDataItem = tableData.get(0).get(column); if (recordDataItem.isValueNull()) { return String.class; } int columnType = recordDataItem.getDataType(); switch (columnType) { case Types.TINYINT: return Byte.class; case Types.BIGINT: return Long.class; case Types.SMALLINT: return Short.class; case Types.BIT: case Types.LONGVARCHAR: case Types.CHAR: case Types.VARCHAR: case Types.BOOLEAN: // don't display the checkbox return String.class; case Types.NUMERIC: case Types.DECIMAL: return BigDecimal.class; case Types.INTEGER: return Integer.class; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return java.util.Date.class; case Types.REAL: return Float.class; case Types.FLOAT: case Types.DOUBLE: return Double.class; default: return Object.class; } }
From source file:org.apache.openjpa.persistence.jdbc.XMLPersistenceMappingParser.java
/** * Parse temporal./*from w ww.jav a 2 s . c o m*/ */ private void endMapKeyTemporal() { String temp = currentText(); TemporalType _mapKeyTemporal = null; if (!StringUtils.isEmpty(temp)) _mapKeyTemporal = Enum.valueOf(TemporalType.class, temp); FieldMapping fm = (FieldMapping) currentElement(); List<Column> cols = fm.getKeyMapping().getValueInfo().getColumns(); if (cols.isEmpty()) { cols = Arrays.asList(new Column[] { new Column() }); fm.getKeyMapping().getValueInfo().setColumns(cols); } Column col = (Column) cols.get(0); switch (_mapKeyTemporal) { case DATE: col.setType(Types.DATE); break; case TIME: col.setType(Types.TIME); break; case TIMESTAMP: col.setType(Types.TIMESTAMP); break; } }
From source file:org.sakaiproject.warehouse.util.db.DbLoader.java
protected int getJavaSqlType(String genericDataTypeName) { // Find the type code for this generic type name int dataTypeCode = 0; if (genericDataTypeName.equalsIgnoreCase("BIT")) dataTypeCode = Types.BIT; // -7 else if (genericDataTypeName.equalsIgnoreCase("TINYINT")) dataTypeCode = Types.TINYINT; // -6 else if (genericDataTypeName.equalsIgnoreCase("SMALLINT")) dataTypeCode = Types.SMALLINT; // 5 else if (genericDataTypeName.equalsIgnoreCase("INTEGER")) dataTypeCode = Types.INTEGER; // 4 else if (genericDataTypeName.equalsIgnoreCase("BIGINT")) dataTypeCode = Types.BIGINT; // -5 else if (genericDataTypeName.equalsIgnoreCase("FLOAT")) dataTypeCode = Types.FLOAT; // 6 else if (genericDataTypeName.equalsIgnoreCase("REAL")) dataTypeCode = Types.REAL; // 7 else if (genericDataTypeName.equalsIgnoreCase("DOUBLE")) dataTypeCode = Types.DOUBLE; // 8 else if (genericDataTypeName.equalsIgnoreCase("NUMERIC")) dataTypeCode = Types.NUMERIC; // 2 else if (genericDataTypeName.equalsIgnoreCase("DECIMAL")) dataTypeCode = Types.DECIMAL; // 3 else if (genericDataTypeName.equalsIgnoreCase("CHAR")) dataTypeCode = Types.CHAR; // 1 else if (genericDataTypeName.equalsIgnoreCase("VARCHAR")) dataTypeCode = Types.VARCHAR; // 12 else if (genericDataTypeName.equalsIgnoreCase("LONGVARCHAR")) dataTypeCode = Types.LONGVARCHAR; // -1 else if (genericDataTypeName.equalsIgnoreCase("DATE")) dataTypeCode = Types.DATE; // 91 else if (genericDataTypeName.equalsIgnoreCase("TIME")) dataTypeCode = Types.TIME; // 92 else if (genericDataTypeName.equalsIgnoreCase("TIMESTAMP")) dataTypeCode = Types.TIMESTAMP; // 93 else if (genericDataTypeName.equalsIgnoreCase("BINARY")) dataTypeCode = Types.BINARY; // -2 else if (genericDataTypeName.equalsIgnoreCase("VARBINARY")) dataTypeCode = Types.VARBINARY; // -3 else if (genericDataTypeName.equalsIgnoreCase("LONGVARBINARY")) dataTypeCode = Types.LONGVARBINARY; // -4 else if (genericDataTypeName.equalsIgnoreCase("NULL")) dataTypeCode = Types.NULL; // 0 else if (genericDataTypeName.equalsIgnoreCase("OTHER")) dataTypeCode = Types.OTHER; // 1111 else if (genericDataTypeName.equalsIgnoreCase("JAVA_OBJECT")) dataTypeCode = Types.JAVA_OBJECT; // 2000 else if (genericDataTypeName.equalsIgnoreCase("DISTINCT")) dataTypeCode = Types.DISTINCT; // 2001 else if (genericDataTypeName.equalsIgnoreCase("STRUCT")) dataTypeCode = Types.STRUCT; // 2002 else if (genericDataTypeName.equalsIgnoreCase("ARRAY")) dataTypeCode = Types.ARRAY; // 2003 else if (genericDataTypeName.equalsIgnoreCase("BLOB")) dataTypeCode = Types.BLOB; // 2004 else if (genericDataTypeName.equalsIgnoreCase("CLOB")) dataTypeCode = Types.CLOB; // 2005 else if (genericDataTypeName.equalsIgnoreCase("REF")) dataTypeCode = Types.REF; // 2006 return dataTypeCode; }
From source file:com.streamsets.pipeline.lib.jdbc.JdbcUtil.java
public Field resultToField(ResultSetMetaData md, ResultSet rs, int columnIndex, int maxClobSize, int maxBlobSize, DataType userSpecifiedType, UnknownTypeAction unknownTypeAction, boolean timestampToString) throws SQLException, IOException, StageException { Field field;/*from w w w .ja va 2s . c o m*/ if (userSpecifiedType != DataType.USE_COLUMN_TYPE) { // If user specifies the data type, overwrite the column type returned by database. field = Field.create(Field.Type.valueOf(userSpecifiedType.getLabel()), rs.getObject(columnIndex)); } else { // All types as of JDBC 2.0 are here: // https://docs.oracle.com/javase/8/docs/api/constant-values.html#java.sql.Types.ARRAY // Good source of recommended mappings is here: // http://www.cs.mun.ca/java-api-1.5/guide/jdbc/getstart/mapping.html switch (md.getColumnType(columnIndex)) { case Types.BIGINT: field = Field.create(Field.Type.LONG, rs.getObject(columnIndex)); break; case Types.BINARY: case Types.LONGVARBINARY: case Types.VARBINARY: field = Field.create(Field.Type.BYTE_ARRAY, rs.getBytes(columnIndex)); break; case Types.BIT: case Types.BOOLEAN: field = Field.create(Field.Type.BOOLEAN, rs.getObject(columnIndex)); break; case Types.CHAR: case Types.LONGNVARCHAR: case Types.LONGVARCHAR: case Types.NCHAR: case Types.NVARCHAR: case Types.VARCHAR: field = Field.create(Field.Type.STRING, rs.getObject(columnIndex)); break; case Types.CLOB: case Types.NCLOB: field = Field.create(Field.Type.STRING, getClobString(rs.getClob(columnIndex), maxClobSize)); break; case Types.BLOB: field = Field.create(Field.Type.BYTE_ARRAY, getBlobBytes(rs.getBlob(columnIndex), maxBlobSize)); break; case Types.DATE: field = Field.create(Field.Type.DATE, rs.getDate(columnIndex)); break; case Types.DECIMAL: case Types.NUMERIC: field = Field.create(Field.Type.DECIMAL, rs.getBigDecimal(columnIndex)); field.setAttribute(HeaderAttributeConstants.ATTR_SCALE, String.valueOf(rs.getMetaData().getScale(columnIndex))); field.setAttribute(HeaderAttributeConstants.ATTR_PRECISION, String.valueOf(rs.getMetaData().getPrecision(columnIndex))); break; case Types.DOUBLE: field = Field.create(Field.Type.DOUBLE, rs.getObject(columnIndex)); break; case Types.FLOAT: case Types.REAL: field = Field.create(Field.Type.FLOAT, rs.getObject(columnIndex)); break; case Types.INTEGER: field = Field.create(Field.Type.INTEGER, rs.getObject(columnIndex)); break; case Types.ROWID: field = Field.create(Field.Type.STRING, rs.getRowId(columnIndex).toString()); break; case Types.SMALLINT: case Types.TINYINT: field = Field.create(Field.Type.SHORT, rs.getObject(columnIndex)); break; case Types.TIME: field = Field.create(Field.Type.TIME, rs.getObject(columnIndex)); break; case Types.TIMESTAMP: final Timestamp timestamp = rs.getTimestamp(columnIndex); if (timestampToString) { field = Field.create(Field.Type.STRING, timestamp == null ? null : timestamp.toString()); } else { field = Field.create(Field.Type.DATETIME, timestamp); if (timestamp != null) { final long actualNanos = timestamp.getNanos() % NANOS_TO_MILLIS_ADJUSTMENT; if (actualNanos > 0) { field.setAttribute(FIELD_ATTRIBUTE_NANOSECONDS, String.valueOf(actualNanos)); } } } break; // Ugly hack until we can support LocalTime, LocalDate, LocalDateTime, etc. case Types.TIME_WITH_TIMEZONE: OffsetTime offsetTime = rs.getObject(columnIndex, OffsetTime.class); field = Field.create(Field.Type.TIME, Date.from(offsetTime.atDate(LocalDate.MIN).toInstant())); break; case Types.TIMESTAMP_WITH_TIMEZONE: OffsetDateTime offsetDateTime = rs.getObject(columnIndex, OffsetDateTime.class); field = Field.create(Field.Type.ZONED_DATETIME, offsetDateTime.toZonedDateTime()); break; //case Types.REF_CURSOR: // JDK8 only case Types.SQLXML: case Types.STRUCT: case Types.ARRAY: case Types.DATALINK: case Types.DISTINCT: case Types.JAVA_OBJECT: case Types.NULL: case Types.OTHER: case Types.REF: default: if (unknownTypeAction == null) { return null; } switch (unknownTypeAction) { case STOP_PIPELINE: throw new StageException(JdbcErrors.JDBC_37, md.getColumnType(columnIndex), md.getColumnLabel(columnIndex)); case CONVERT_TO_STRING: Object value = rs.getObject(columnIndex); if (value != null) { field = Field.create(Field.Type.STRING, rs.getObject(columnIndex).toString()); } else { field = Field.create(Field.Type.STRING, null); } break; default: throw new IllegalStateException("Unknown action: " + unknownTypeAction); } } } return field; }
From source file:fr.aliacom.obm.common.calendar.CalendarDaoJdbcImpl.java
private int fillEventStatement(PreparedStatement ps, Event ev, AccessToken at, int i) throws SQLException { int idx = i;//from w w w .j a v a2 s .com ps.setString(idx++, ev.getExtId().getExtId()); ps.setString(idx++, ev.getTimezoneName()); ps.setObject(idx++, obmHelper.getDBCP().getJdbcObject(ObmHelper.VOPACITY, ev.getOpacity().toString())); ps.setString(idx++, ev.getTitle()); ps.setString(idx++, ev.getLocation()); Integer cat = catIdFromString(ps.getConnection(), ev.getCategory(), at.getDomain().getId()); if (cat != null) { ps.setInt(idx++, cat); } else { ps.setNull(idx++, Types.INTEGER); } ps.setInt(idx++, RFC2445.getPriorityOrDefault(ev.getPriority())); ps.setInt(idx++, ev.getPrivacy().toInteger()); if (ev.getStartDate() != null) { ps.setTimestamp(idx++, new Timestamp(ev.getStartDate().getTime())); } else { ps.setNull(idx++, Types.DATE); } ps.setInt(idx++, ev.getDuration()); ps.setBoolean(idx++, ev.isAllday()); EventRecurrence r = ev.getRecurrence(); ps.setString(idx++, r.getKind().toString()); ps.setInt(idx++, r.getFrequence()); ps.setString(idx++, new RecurrenceDaysSerializer().serialize(r.getDays())); if (r.getEnd() != null) { ps.setTimestamp(idx++, new Timestamp(r.getEnd().getTime())); } else { ps.setNull(idx++, Types.DATE); } ps.setNull(idx++, Types.VARCHAR); // color ps.setNull(idx++, Types.DATE); // FIXME completed ps.setNull(idx++, Types.VARCHAR); // FIXME url ps.setString(idx++, ev.getDescription()); ps.setInt(idx++, at.getDomain().getId()); ps.setString(idx++, at.getOrigin()); ps.setObject(idx++, obmHelper.getDBCP().getJdbcObject(ObmHelper.VCOMPONENT, ev.getType().toString())); ps.setInt(idx++, ev.getSequence()); return idx; }
From source file:org.jumpmind.symmetric.db.sqlanywhere.SqlAnywhereTriggerTemplate.java
@Override protected String buildKeyVariablesDeclare(Column[] columns, String prefix) { String text = ""; for (int i = 0; i < columns.length; i++) { text += "declare @" + prefix + "pk" + i + " "; switch (columns[i].getMappedTypeCode()) { case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: text += "bigint\n"; break; case Types.NUMERIC: case Types.DECIMAL: text += "decimal\n"; break; case Types.FLOAT: case Types.REAL: case Types.DOUBLE: text += "float\n"; break; case Types.CHAR: case Types.VARCHAR: case ColumnTypes.NVARCHAR: case ColumnTypes.LONGNVARCHAR: case Types.LONGVARCHAR: text += "varchar(1000)\n"; break; case Types.DATE: text += "date\n"; break; case Types.TIME: text += "time\n"; break; case Types.TIMESTAMP: text += "datetime\n"; break; case Types.BOOLEAN: case Types.BIT: text += "bit\n"; break; case Types.CLOB: text += "varchar(16384)\n"; break; case Types.BLOB: case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: case -10: // SQL-Server ntext binary type text += "varbinary(16384)\n"; break; case Types.OTHER: text += "varbinary(16384)\n"; break; default://from www.j a va 2s. c o m if (columns[i].getJdbcTypeName() != null && columns[i].getJdbcTypeName().equalsIgnoreCase("interval")) { text += "interval"; break; } throw new NotImplementedException(columns[i] + " is of type " + columns[i].getMappedType()); } } return text; }
From source file:org.apache.openjpa.jdbc.schema.Column.java
/** * Return true if this column is compatible with the given JDBC type * from {@link Types} and size./*from w w w . j ava 2 s . c o m*/ */ public boolean isCompatible(int type, String typeName, int size, int decimals) { if (type == Types.OTHER || getType() == Types.OTHER) return true; // note that the given size is currently ignored, but may be useful // to dynamically-populating subclasses switch (getType()) { case Types.BIT: case Types.TINYINT: case Types.BIGINT: case Types.INTEGER: case Types.NUMERIC: case Types.SMALLINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: switch (type) { case Types.BIT: case Types.TINYINT: case Types.BIGINT: case Types.INTEGER: case Types.NUMERIC: case Types.SMALLINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: return true; default: return false; } case Types.BINARY: case Types.BLOB: case Types.LONGVARBINARY: case Types.VARBINARY: case Types.OTHER: switch (type) { case Types.BINARY: case Types.BLOB: case Types.LONGVARBINARY: case Types.VARBINARY: case Types.OTHER: return true; default: return false; } case Types.CLOB: case Types.CHAR: case Types.LONGVARCHAR: case Types.VARCHAR: switch (type) { case Types.CLOB: case Types.CHAR: case Types.LONGVARCHAR: case Types.VARCHAR: case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return true; default: return false; } case Types.DATE: case Types.TIME: case Types.TIMESTAMP: switch (type) { case Types.LONGVARCHAR: case Types.CLOB: case Types.VARCHAR: case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return true; default: return false; } case 2007: // Oracle-defined opaque type code for XMLType switch (type) { case Types.CHAR: case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CLOB: case Types.BLOB: return true; default: return false; } default: return type == getType(); } }
From source file:ca.sqlpower.architect.ddl.LiquibaseDDLGenerator.java
private boolean isDateType(GenericTypeDescriptor td) { int type = td.getDataType(); return (type == Types.DATE || type == Types.TIMESTAMP); }
From source file:org.jumpmind.db.platform.AbstractDatabasePlatform.java
public java.util.Date parseDate(int type, String value, boolean useVariableDates) { if (StringUtils.isNotBlank(value)) { try {//from w w w .j a va 2 s.c o m boolean useTimestamp = (type == Types.TIMESTAMP) || (type == Types.DATE && getDdlBuilder().getDatabaseInfo().isDateOverridesToTimestamp()); if (useVariableDates && value.startsWith("${curdate")) { long time = Long.parseLong(value.substring(10, value.length() - 1)); if (value.substring(9, 10).equals("-")) { time *= -1L; } time += System.currentTimeMillis(); if (useTimestamp) { return new Timestamp(time); } return new Date(time); } else { if (useTimestamp) { return parseTimestamp(type, value); } else if (type == Types.TIME) { if (value.indexOf(".") == 8) { /* * Firebird (at least) captures fractional seconds * in time fields which need to be parsed by * Timestamp.valueOf */ return Timestamp.valueOf("1970-01-01 " + value); } else { return FormatUtils.parseDate(value, FormatUtils.TIME_PATTERNS); } } else { return FormatUtils.parseDate(value, FormatUtils.TIMESTAMP_PATTERNS); } } } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } } else { return null; } }