當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。