当前位置: 首页>>代码示例>>Java>>正文


Java Types.DATE属性代码示例

本文整理汇总了Java中java.sql.Types.DATE属性的典型用法代码示例。如果您正苦于以下问题:Java Types.DATE属性的具体用法?Java Types.DATE怎么用?Java Types.DATE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在java.sql.Types的用法示例。


在下文中一共展示了Types.DATE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getColumnTypeName

@Override
public String getColumnTypeName(int column) throws SQLException {
	// 数据库特定的类型名称
	switch (keytype[column-1]){
	case  Types.INTEGER: return "INTEGER";
	case  Types.BOOLEAN:  return "BOOLEAN";
	case  Types.BIT: return "BITT"; 
	case  Types.FLOAT: return "FLOAT";
	case  Types.BIGINT: return "BIGINT";
	case  Types.DOUBLE:  return "DOUBLE";
	case  Types.DATE: return "DATE"; 
	case  Types.TIME: return "TIME";
	case  Types.TIMESTAMP: return "TIMESTAMP";
	default: return "varchar";
   }
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:16,代码来源:MongoResultSetMetaData.java

示例2: resultSetColToLong

/**
    Retrieve the value from the column in a type-appropriate manner and
    return its timestamp since the epoch. If the column is null, then return
    Long.MIN_VALUE.  This will cause a special split to be generated for the
    NULL case, but may also cause poorly-balanced splits if most of the
    actual dates are positive time since the epoch, etc.
  */
private long resultSetColToLong(ResultSet rs, int colNum, int sqlDataType)
    throws SQLException {
  try {
    switch (sqlDataType) {
    case Types.DATE:
      return rs.getDate(colNum).getTime();
    case Types.TIME:
      return rs.getTime(colNum).getTime();
    case Types.TIMESTAMP:
      return rs.getTimestamp(colNum).getTime();
    default:
      throw new SQLException("Not a date-type field");
    }
  } catch (NullPointerException npe) {
    // null column. return minimum long value.
    LOG.warn("Encountered a NULL date in the split column. "
        + "Splits may be poorly balanced.");
    return Long.MIN_VALUE;
  }
}
 
开发者ID:BriData,项目名称:DBus,代码行数:27,代码来源:DateSplitter.java

示例3: setDate

/**
 * Set a parameter to a java.sql.Date value. The driver converts this to a
 * SQL DATE value when it sends it to the database.
 * 
 * @param parameterIndex
 *            the first parameter is 1, the second is 2, ...
 * @param x
 *            the parameter value
 * @param cal
 *            the calendar to interpret the date with
 * 
 * @exception SQLException
 *                if a database-access error occurs.
 */
public void setDate(int parameterIndex, java.sql.Date x, Calendar cal) throws SQLException {
    if (x == null) {
        setNull(parameterIndex, java.sql.Types.DATE);
    } else {
        if (!this.useLegacyDatetimeCode) {
            newSetDateInternal(parameterIndex, x, cal);
        } else {
            synchronized (checkClosed().getConnectionMutex()) {
                if (this.ddf == null) {
                    this.ddf = new SimpleDateFormat("''yyyy-MM-dd''", Locale.US);
                }
                if (cal != null) {
                    this.ddf.setTimeZone(cal.getTimeZone());
                }

                setInternal(parameterIndex, this.ddf.format(x));

                this.parameterTypes[parameterIndex - 1 + getParameterIndexOffset()] = Types.DATE;
            }
        }
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:36,代码来源:PreparedStatement.java

示例4: getSelectClauseNullString

@Override
public String getSelectClauseNullString(int sqlType) {
	String literal;
	switch ( sqlType ) {
		case Types.LONGVARCHAR:
		case Types.VARCHAR:
		case Types.CHAR:
			literal = "cast(null as varchar(100))";
			break;
		case Types.LONGVARBINARY:
		case Types.VARBINARY:
		case Types.BINARY:
			literal = "cast(null as varbinary(100))";
			break;
		case Types.CLOB:
			literal = "cast(null as clob)";
			break;
		case Types.BLOB:
			literal = "cast(null as blob)";
			break;
		case Types.DATE:
			literal = "cast(null as date)";
			break;
		case Types.TIMESTAMP:
			literal = "cast(null as timestamp)";
			break;
		case Types.BOOLEAN:
			literal = "cast(null as boolean)";
			break;
		case Types.BIT:
			literal = "cast(null as bit)";
			break;
		case Types.TIME:
			literal = "cast(null as time)";
			break;
		default:
			literal = "cast(null as int)";
	}
	return literal;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:40,代码来源:HSQLDialect.java

示例5: getSplitter

/**
 * @return the DBSplitter implementation to use to divide the table/query into InputSplits.
 */
protected DBSplitter getSplitter(int sqlDataType) {
  switch (sqlDataType) {
  case Types.NUMERIC:
  case Types.DECIMAL:
    return new BigDecimalSplitter();

  case Types.BIT:
  case Types.BOOLEAN:
    return new BooleanSplitter();

  case Types.INTEGER:
  case Types.TINYINT:
  case Types.SMALLINT:
  case Types.BIGINT:
    return new IntegerSplitter();

  case Types.REAL:
  case Types.FLOAT:
  case Types.DOUBLE:
    return new FloatSplitter();

  case Types.CHAR:
  case Types.VARCHAR:
  case Types.LONGVARCHAR:
    return new TextSplitter();

  case Types.DATE:
  case Types.TIME:
  case Types.TIMESTAMP:
    return new DateSplitter();

  default:
    // TODO: Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT, CLOB, BLOB, ARRAY
    // STRUCT, REF, DATALINK, and JAVA_OBJECT.
    return null;
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:40,代码来源:DataDrivenDBInputFormat.java

示例6: columnClassNames

@DataProvider(name = "columnClassNames")
private Object[][] columnClassNames() {
    return new Object[][]{
        {Types.CHAR, "java.lang.String"},
        {Types.NCHAR, "java.lang.String"},
        {Types.VARCHAR, "java.lang.String"},
        {Types.NVARCHAR, "java.lang.String"},
        {Types.LONGVARCHAR, "java.lang.String"},
        {Types.LONGNVARCHAR, "java.lang.String"},
        {Types.NUMERIC, "java.math.BigDecimal"},
        {Types.DECIMAL, "java.math.BigDecimal"},
        {Types.BIT, "java.lang.Boolean"},
        {Types.TINYINT, "java.lang.Byte"},
        {Types.SMALLINT, "java.lang.Short"},
        {Types.INTEGER, "java.lang.Integer"},
        {Types.FLOAT, "java.lang.Double"},
        {Types.DOUBLE, "java.lang.Double"},
        {Types.BINARY, "byte[]"},
        {Types.VARBINARY, "byte[]"},
        {Types.LONGVARBINARY, "byte[]"},
        {Types.DATE, "java.sql.Date"},
        {Types.TIME, "java.sql.Time"},
        {Types.TIMESTAMP, "java.sql.Timestamp"},
        {Types.CLOB, "java.sql.Clob"},
        {Types.BLOB, "java.sql.Blob"}

    };

}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:29,代码来源:RowSetMetaDataTests.java

示例7: datetimeToQueryString

@Override
public String datetimeToQueryString(String datetime, int columnType) {
  if (columnType == Types.TIMESTAMP) {
    return "TO_TIMESTAMP('" + datetime + "', 'YYYY-MM-DD HH24:MI:SS.FF')";
  } else if (columnType == Types.DATE) {
    // converting timestamp of the form 2012-11-11 11:11:11.00 to
    // date of the form 2011:11:11 11:11:11
    datetime = datetime.split("\\.")[0];
    return "TO_DATE('" + datetime + "', 'YYYY-MM-DD HH24:MI:SS')";
  } else {
    String msg = "Column type is neither timestamp nor date!";
    LOG.error(msg);
    throw new RuntimeException(msg);
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:15,代码来源:OracleManager.java

示例8: longToDate

/**  Parse the long-valued timestamp into the appropriate SQL date type. */
public static Date longToDate(long val, int sqlDataType) {
  switch (sqlDataType) {
  case Types.DATE:
    return new java.sql.Date(val);
  case Types.TIME:
    return new java.sql.Time(val);
  case Types.TIMESTAMP:
    return new java.sql.Timestamp(val);
  default: // Shouldn't ever hit this case.
    return null;
  }
}
 
开发者ID:BriData,项目名称:DBus,代码行数:13,代码来源:DateSplitter.java

示例9: getColumnClass

@Override
public Class<?> getColumnClass(int column) {
    int type;
    try {
        type = metaData.getColumnType(column + 1);
    } catch (SQLException e) {
        return super.getColumnClass(column);
    }

    switch (type) {
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            return String.class;

        case Types.BIT:
            return Boolean.class;

        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
            return Integer.class;

        case Types.BIGINT:
            return Long.class;

        case Types.FLOAT:
        case Types.DOUBLE:
            return Double.class;

        case Types.DATE:
            return java.sql.Date.class;

        default:
            return Object.class;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:37,代码来源:JDBCAdapter.java

示例10: getObjectToType

public static int getObjectToType(Object ob){
if (ob instanceof Integer) {
	return Types.INTEGER;
}
else if (ob instanceof Boolean) {
	return Types.BOOLEAN;
}
else if (ob instanceof Byte) {
	return Types.BIT;
}	
else if (ob instanceof Short) {
	return Types.INTEGER;
}	
else if (ob instanceof Float) {
	return Types.FLOAT;
}			
else if (ob instanceof Long) {
	return Types.BIGINT;
}
else if (ob instanceof Double) {
	return Types.DOUBLE;
}			
else if (ob instanceof Date) {
	return Types.DATE;
}	
else if (ob instanceof Time) {
	return Types.TIME;
}	
else if (ob instanceof Timestamp) {
	return Types.TIMESTAMP;
}
else if (ob instanceof String) {
	return Types.VARCHAR;
}			
else  {
	return Types.VARCHAR;
}	   
 }
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:38,代码来源:MongoData.java

示例11: getSelectClauseNullString

public String getSelectClauseNullString(int sqlType) {
        String literal;
        switch ( sqlType ) {
                case Types.LONGVARCHAR:
                case Types.VARCHAR:
                case Types.CHAR:
                        literal = "cast(null as varchar(100))";
                        break;
                case Types.LONGVARBINARY:
                case Types.VARBINARY:
                case Types.BINARY:
                        literal = "cast(null as varbinary(100))";
                        break;
                case Types.CLOB:
                        literal = "cast(null as clob)";
                        break;
                case Types.BLOB:
                        literal = "cast(null as blob)";
                        break;
                case Types.DATE:
                        literal = "cast(null as date)";
                        break;
                case Types.TIMESTAMP:
                        literal = "cast(null as timestamp)";
                        break;
                case Types.BOOLEAN:
                        literal = "cast(null as boolean)";
                        break;
                case Types.BIT:
                        literal = "cast(null as bit)";
                        break;
                case Types.TIME:
                        literal = "cast(null as time)";
                        break;
                default:
                        literal = "cast(null as int)";
        }
        return literal;
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:39,代码来源:HSQLDialect.java

示例12: doPreparedStatement

private void doPreparedStatement(PreparedStatement ps, final DbDialect dbDialect, final Integer[] columnTypes,
                                 final String[] columnValues) throws SQLException {
    LobCreator lobCreator = null;
    for (int i = 0; i < columnTypes.length; i++) {
        int paramIndex = i + 1;
        String sqlValue = columnValues[i];
        int sqlType = columnTypes[i];
        Object param = SqlUtils.stringToSqlValue(sqlValue,
            sqlType,
            SqlUtils.isTextType(sqlType),
            dbDialect.isEmptyStringNulled());
        switch (sqlType) {
            case Types.CLOB:
                if (lobCreator == null) {
                    lobCreator = dbDialect.getLobHandler().getLobCreator();
                }

                lobCreator.setClobAsString(ps, paramIndex, (String) param);
                break;

            case Types.BLOB:
                if (lobCreator == null) {
                    lobCreator = dbDialect.getLobHandler().getLobCreator();
                }

                lobCreator.setBlobAsBytes(ps, paramIndex, (byte[]) param);
                break;
            case Types.TIME:
            case Types.TIMESTAMP:
            case Types.DATE:
                ps.setObject(paramIndex, sqlValue);
                break;
            default:
                StatementCreatorUtils.setParameterValue(ps, paramIndex, sqlType, null, param);
                break;
        }
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:38,代码来源:TimeTableIntegration.java

示例13: getSQLValue

public String getSQLValue(Table table, Row row, int index) {
	Column column = table.getColumns().get(index);
	int type = column.getDataType();
	if (row.get(index) == null) {
		return "null";
	} else {
		switch (type) {
		case Types.CHAR:
		case Types.VARCHAR:
		case Types.LONGNVARCHAR:
		case Types.NCHAR:
		case Types.NVARCHAR:
		case Types.LONGVARCHAR:
			return "\"" + row.getString(index) + "\"";

		case Types.DATE:
			return "\"" + DATE_FORMAT_THREAD_LOCAL.get().format(row.getDate(index)) + "\"";

		case Types.TIME:
			return "\"" + TIME_FORMAT_THREAD_LOCAL.get().format(row.getDate(index)) + "\"";

		case Types.TIMESTAMP:
			return "\"" + DATE_TIME_FORMAT_THREAD_LOCAL.get().format(row.getDate(index)) + "\"";

		default:
			return row.getString(index);
		}

	}
}
 
开发者ID:ZHENFENG13,项目名称:My-Blog,代码行数:30,代码来源:Backup.java

示例14: javaTypeMysql

public static int javaTypeMysql(int javaType) {

		switch (javaType) {
		case Types.NUMERIC:
			return MysqlDefs.FIELD_TYPE_DECIMAL;

		case Types.DECIMAL:
			return MysqlDefs.FIELD_TYPE_NEW_DECIMAL;

		case Types.TINYINT:
			return MysqlDefs.FIELD_TYPE_TINY;

		case Types.SMALLINT:
			return MysqlDefs.FIELD_TYPE_SHORT;

		case Types.INTEGER:
			return MysqlDefs.FIELD_TYPE_LONG;

		case Types.REAL:
			return MysqlDefs.FIELD_TYPE_FLOAT;

		case Types.DOUBLE:
			return MysqlDefs.FIELD_TYPE_DOUBLE;

		case Types.NULL:
			return MysqlDefs.FIELD_TYPE_NULL;

		case Types.TIMESTAMP:
			return MysqlDefs.FIELD_TYPE_TIMESTAMP;

		case Types.BIGINT:
			return MysqlDefs.FIELD_TYPE_LONGLONG;

		case Types.DATE:
			return MysqlDefs.FIELD_TYPE_DATE;

		case Types.TIME:
			return MysqlDefs.FIELD_TYPE_TIME;

		case Types.VARBINARY:
			return MysqlDefs.FIELD_TYPE_TINY_BLOB;

		case Types.LONGVARBINARY:
			return MysqlDefs.FIELD_TYPE_BLOB;
            //对应sqlserver的image类型
            case 27:
                return MysqlDefs.FIELD_TYPE_BLOB;

		case Types.VARCHAR:
			return MysqlDefs.FIELD_TYPE_VAR_STRING;

		case Types.CHAR:
			return MysqlDefs.FIELD_TYPE_STRING;

		case Types.BINARY:
			return MysqlDefs.FIELD_TYPE_GEOMETRY;

		case Types.BIT:
			return MysqlDefs.FIELD_TYPE_BIT;
		case Types.CLOB:
			return MysqlDefs.FIELD_TYPE_VAR_STRING;
		case Types.BLOB:
			return MysqlDefs.FIELD_TYPE_BLOB;

		//修改by     [email protected]
		// 当jdbc连接非mysql的数据库时,需要把对应类型映射为mysql的类型,否则应用端会出错
			case Types.NVARCHAR:
				return MysqlDefs.FIELD_TYPE_VAR_STRING;
			case Types.NCHAR:
				return MysqlDefs.FIELD_TYPE_STRING;
			case Types.NCLOB:
				return MysqlDefs.FIELD_TYPE_VAR_STRING;
			case Types.LONGNVARCHAR:
				return MysqlDefs.FIELD_TYPE_VAR_STRING;

		default:
			return MysqlDefs.FIELD_TYPE_VAR_STRING;   //其他未知类型返回字符类型
		//	return Types.VARCHAR;
		}

	}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:81,代码来源:MysqlDefs.java

示例15: getEstimatedRowSizeInCloudSpanner

/**
 * @param connection
 *            The connection to use to estimate the row size
 * @param catalog
 *            The catalog of the table
 * @param schemaPattern
 *            The schema of the table
 * @param tableNamePattern
 *            The name of the table
 * @param columnNamePattern
 *            The name of the column(s) to check
 * @return The estimated size in bytes of one row of the specified columns
 *         of the specified table
 * @throws SQLException
 *             If a database error occurs while getting the table meta data
 */
public static int getEstimatedRowSizeInCloudSpanner(Connection connection, String catalog, String schemaPattern,
		String tableNamePattern, String columnNamePattern) throws SQLException
{
	// There's an 8 bytes storage overhead for each column
	int totalSize = 8;
	try (ResultSet rs = connection.getMetaData().getColumns(catalog, schemaPattern, tableNamePattern,
			columnNamePattern))
	{
		while (rs.next())
		{
			long colLength = rs.getLong("COLUMN_SIZE");
			int colType = rs.getInt("DATA_TYPE");
			switch (colType)
			{
			case Types.ARRAY:
				break;
			case Types.BOOLEAN:
				totalSize += 1;
				break;
			case Types.BINARY:
				totalSize += colLength;
				break;
			case Types.DATE:
				totalSize += 4;
				break;
			case Types.DOUBLE:
				totalSize += 8;
				break;
			case Types.BIGINT:
				totalSize += 8;
				break;
			case Types.NVARCHAR:
				totalSize += colLength * 2;
				break;
			case Types.TIMESTAMP:
				totalSize += 12;
				break;
			}
		}
	}
	return totalSize;
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:58,代码来源:ConverterUtils.java


注:本文中的java.sql.Types.DATE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。