Java Code Examples for java.sql.Types#TIME

The following examples show how to use java.sql.Types#TIME . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PreparedStatement.java    From r-course with MIT License 6 votes vote down vote up
/**
 * Set a parameter to a java.sql.Time value. The driver converts this to a
 * SQL TIME value when it sends it to the database, using the given
 * timezone.
 * 
 * @param parameterIndex
 *            the first parameter is 1...));
 * @param x
 *            the parameter value
 * @param tz
 *            the timezone to use
 * 
 * @throws java.sql.SQLException
 *             if a database access error occurs
 */
private void setTimeInternal(int parameterIndex, Time x, Calendar targetCalendar, TimeZone tz, boolean rollForward) throws java.sql.SQLException {
    if (x == null) {
        setNull(parameterIndex, java.sql.Types.TIME);
    } else {
        checkClosed();

        if (!this.useLegacyDatetimeCode) {
            newSetTimeInternal(parameterIndex, x, targetCalendar);
        } else {
            Calendar sessionCalendar = getCalendarInstanceForSessionOrNew();

            x = TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, x, tz, this.connection.getServerTimezoneTZ(), rollForward);

            setInternal(parameterIndex, "'" + x.toString() + "'");
        }

        this.parameterTypes[parameterIndex - 1 + getParameterIndexOffset()] = Types.TIME;
    }
}
 
Example 2
Source File: TimeTypeCompiler.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * User types are storable into other user types that they
 * are assignable to. The other type must be a subclass of
 * this type, or implement this type as one of its interfaces.
 *
 * Built-in types are also storable into user types when the built-in
 * type's corresponding Java type is assignable to the user type.
 *
 * @param otherType the type of the instance to store into this type.
 * @param cf		A ClassFactory
 * @return true if otherType is storable into this type, else false.
 */
public boolean storable(TypeId otherType, ClassFactory cf)
{
	int	otherJDBCTypeId = otherType.getJDBCTypeId();

	if (otherJDBCTypeId == Types.TIME ||
		(otherJDBCTypeId == Types.CHAR) ||
		(otherJDBCTypeId == Types.VARCHAR))
	{
		return true;
	}

	return cf.getClassInspector().assignableTo(
		   otherType.getCorrespondingJavaTypeName(),
		   "java.sql.Time");
}
 
Example 3
Source File: AttributeSetup.java    From celerio with Apache License 2.0 6 votes vote down vote up
private MappedType getMappedTypeByGlobalMappingConfiguration() {

        switch (attribute.getJdbcType().getJdbcType()) {
            case Types.BIGINT:
            case Types.DOUBLE:
            case Types.FLOAT:
            case Types.INTEGER:
            case Types.SMALLINT:
            case Types.TINYINT:
            case Types.DECIMAL:
            case Types.NUMERIC:
            case Types.REAL:
                // a number, we can continue.
                return getNumberMappedType();

            case Types.DATE:
            case Types.TIME:
            case Types.TIMESTAMP:
                return getDateMappedType();
            default:
                // the number mapping does not apply.
                return null;
        }
    }
 
Example 4
Source File: SequoiaData.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
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;
}	   
 }
 
Example 5
Source File: Heading.java    From sql4es with Apache License 2.0 5 votes vote down vote up
public static int getTypeIdForObject(Object c) {
	if (c instanceof Long)
		return Types.BIGINT;
	if (c instanceof Boolean)
		return Types.BOOLEAN;
	if (c instanceof Character)
		return Types.CHAR;
	if (c instanceof Timestamp)
		return Types.TIMESTAMP;
	if (c instanceof java.sql.Date)
		return Types.DATE;
	if (c instanceof java.util.Date)
		return Types.DATE;
	if (c instanceof Double)
		return Types.DOUBLE;
	if (c instanceof Integer)
		return Types.INTEGER;
	if (c instanceof BigDecimal)
		return Types.NUMERIC;
	if (c instanceof Short)
		return Types.SMALLINT;
	if (c instanceof Float)
		return Types.FLOAT;
	if (c instanceof String)
		return Types.VARCHAR;
	if (c instanceof Time)
		return Types.TIME;
	if (c instanceof Byte)
		return Types.TINYINT;
	if (c instanceof Byte[])
		return Types.VARBINARY;
	if(c instanceof Object[])
		return Types.JAVA_OBJECT;
	if(c instanceof Object)
		return Types.JAVA_OBJECT;
	if (c instanceof Array)
		return Types.ARRAY;
	else
		return Types.OTHER;
}
 
Example 6
Source File: JdbcPipelineResult.java    From Quicksql with MIT License 5 votes vote down vote up
private void fillWithDisplaySize(int[] type, int[] colCounts) {
    for (int i = 0; i < type.length; i++) {
        switch (type[i]) {
            case Types.BOOLEAN:
            case Types.TINYINT:
            case Types.SMALLINT:
                colCounts[i] = 4;
                break;
            case Types.INTEGER:
            case Types.BIGINT:
            case Types.REAL:
            case Types.FLOAT:
            case Types.DOUBLE:
                colCounts[i] = 8;
                break;
            case Types.CHAR:
            case Types.VARCHAR:
                colCounts[i] = 20;
                break;
            case Types.DATE:
            case Types.TIME:
            case Types.TIMESTAMP:
                colCounts[i] = 20;
                break;
            default:
                colCounts[i] = 20;
        }
    }
}
 
Example 7
Source File: TimestampTypeCompiler.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * User types are convertible to other user types only if
 * (for now) they are the same type and are being used to
 * implement some JDBC type.  This is sufficient for
 * date/time types; it may be generalized later for e.g.
 * comparison of any user type with one of its subtypes.
 *
 * @see TypeCompiler#convertible 
 *
 */
public boolean convertible(TypeId otherType, 
						   boolean forDataTypeFunction)
{
	if (otherType.isStringTypeId()&& 
		(!otherType.isLongConcatableTypeId()))
	{
		return true;
	}
	
	int otherJDBCTypeId = otherType.getJDBCTypeId();

	/*
	** At this point, we have only date/time.  If
	** same type, convert always ok.
	*/
	if (otherJDBCTypeId == Types.TIMESTAMP)
	{
		return true;
	}

	/*
	** Otherwise, we can convert timestamp to
	** date or time only.
	*/
	return ((otherJDBCTypeId == Types.DATE) ||
			(otherJDBCTypeId == Types.TIME));
}
 
Example 8
Source File: QuicksqlServerResultSet.java    From Quicksql with MIT License 4 votes vote down vote up
private static Object getValue(ResultSet resultSet, int type, int j,
    Calendar calendar) throws SQLException {
  switch (type) {
  case Types.BIGINT:
    final long aLong = resultSet.getLong(j + 1);
    return aLong == 0 && resultSet.wasNull() ? null : aLong;
  case Types.INTEGER:
    final int anInt = resultSet.getInt(j + 1);
    return anInt == 0 && resultSet.wasNull() ? null : anInt;
  case Types.SMALLINT:
    final short aShort = resultSet.getShort(j + 1);
    return aShort == 0 && resultSet.wasNull() ? null : aShort;
  case Types.TINYINT:
    final byte aByte = resultSet.getByte(j + 1);
    return aByte == 0 && resultSet.wasNull() ? null : aByte;
  case Types.DOUBLE:
  case Types.FLOAT:
    final double aDouble = resultSet.getDouble(j + 1);
    return aDouble == 0D && resultSet.wasNull() ? null : aDouble;
  case Types.REAL:
    final float aFloat = resultSet.getFloat(j + 1);
    return aFloat == 0D && resultSet.wasNull() ? null : aFloat;
  case Types.DATE:
    final Date aDate = resultSet.getDate(j + 1, calendar);
    return aDate == null
        ? null
        : (int) (aDate.getTime() / DateTimeUtils.MILLIS_PER_DAY);
  case Types.TIME:
    final Time aTime = resultSet.getTime(j + 1, calendar);
    return aTime == null
        ? null
        : (int) (aTime.getTime() % DateTimeUtils.MILLIS_PER_DAY);
  case Types.TIMESTAMP:
    final Timestamp aTimestamp = resultSet.getTimestamp(j + 1, calendar);
    return aTimestamp == null ? null : aTimestamp.getTime();
  case Types.ARRAY:
    final Array array = resultSet.getArray(j + 1);
    if (null == array) {
      return null;
    }
    try {
      // Recursively extracts an Array using its ResultSet-representation
      return extractUsingResultSet(array, calendar);
    } catch (UnsupportedOperationException | SQLFeatureNotSupportedException e) {
      // Not every database might implement Array.getResultSet(). This call
      // assumes a non-nested array (depends on the db if that's a valid assumption)
      return extractUsingArray(array, calendar);
    }
  case Types.STRUCT:
    Struct struct = resultSet.getObject(j + 1, Struct.class);
    Object[] attrs = struct.getAttributes();
    List<Object> list = new ArrayList<>(attrs.length);
    for (Object o : attrs) {
      list.add(o);
    }
    return list;
  default:
    return resultSet.getObject(j + 1);
  }
}
 
Example 9
Source File: DataTypeUtil.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Converts an ODA data type code to the Java class
 * of its corresponding Data Engine ODI data type. <br><br>
 * <b>ODA Data Type -> ODI Type Class</b><br>
 * <i>Integer -> java.lang.Integer<br>
 * Double -> java.lang.Double<br>
 * Character -> java.lang.String<br>
 * Decimal -> java.math.BigDecimal<br>
 * Date -> java.sql.Date<br>
 * Time -> java.sql.Time<br>
 * Timestamp -> java.sql.Timestamp<br>
 * Blob -> java.sql.Blob<br>
 * Clob -> java.sql.Clob<br>
    * Boolean -> java.lang.Boolean<br>
    * JavaObject -> java.lang.Object<br>
    * </i>
 * @param odaDataTypeCode   an ODA data type code
 * @return  the ODI type class that corresponds with 
 *          the specified ODA data type
 * @throws BirtException if the specified ODA data type is not a supported type
 */
public static Class toOdiTypeClass( int odaDataTypeCode )
		throws BirtException
{
	if ( odaDataTypeCode != Types.CHAR
			&& odaDataTypeCode != Types.INTEGER
			&& odaDataTypeCode != Types.DOUBLE
			&& odaDataTypeCode != Types.DECIMAL
			&& odaDataTypeCode != Types.DATE
			&& odaDataTypeCode != Types.TIME
			&& odaDataTypeCode != Types.TIMESTAMP
			&& odaDataTypeCode != Types.BLOB
			&& odaDataTypeCode != Types.CLOB
               && odaDataTypeCode != Types.BOOLEAN
               && odaDataTypeCode != Types.JAVA_OBJECT
			&& odaDataTypeCode != Types.NULL )
	{
		throw new CoreException( ResourceConstants.INVALID_TYPE);
	}

	Class fieldClass = null;
	switch ( odaDataTypeCode )
	{
		case Types.CHAR :
			fieldClass = String.class;
			break;

		case Types.INTEGER :
			fieldClass = Integer.class;
			break;

		case Types.DOUBLE :
			fieldClass = Double.class;
			break;

		case Types.DECIMAL :
			fieldClass = BigDecimal.class;
			break;

		case Types.DATE :
			fieldClass = java.sql.Date.class;
			break;

		case Types.TIME :
			fieldClass = Time.class;
			break;

		case Types.TIMESTAMP :
			fieldClass = Timestamp.class;
			break;

		case Types.BLOB :
			fieldClass = Blob.class;
			break;

		case Types.CLOB :
			fieldClass = Clob.class;
			break;

           case Types.BOOLEAN :
               fieldClass = Boolean.class;
               break;

           case Types.JAVA_OBJECT :
               fieldClass = Object.class;
               break;

		case Types.NULL :
			fieldClass = null;
			break;
	}

	return fieldClass;
}
 
Example 10
Source File: EventErrorFileToDBWriter.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Set the value of a parameter in prepared statement given a string
 * representation as returned by
 */
public static void setParameters(PreparedStatement pstmt, String[] params,
    ArrayList<Integer> paramTypes) throws Exception {
  for (int index = 0; index < params.length; index++) {
    String param = params[index];
    int paramIndex = index + 1;
    int paramType = paramTypes.get(index);
    byte[] bytes;

    if (param == null) {
      pstmt.setNull(paramIndex, paramType);
      continue;
    }
    switch (paramType) {
      case Types.BIGINT:
        final long longVal = Long.parseLong(param);
        pstmt.setLong(paramIndex, longVal);
        break;
      case Types.BIT:
      case Types.BOOLEAN:
        final boolean boolVal;
        if ("1".equals(param)) {
          boolVal = true;
        }
        else if ("0".equals(param)) {
          boolVal = false;
        }
        else {
          boolVal = Boolean.parseBoolean(param);
        }
        pstmt.setBoolean(paramIndex, boolVal);
        break;
      case Types.DATE:
        final java.sql.Date dateVal = java.sql.Date.valueOf(param);
        pstmt.setDate(paramIndex, dateVal);
        break;
      case Types.DECIMAL:
      case Types.NUMERIC:
        final BigDecimal decimalVal = new BigDecimal(param);
        pstmt.setBigDecimal(paramIndex, decimalVal);
        break;
      case Types.DOUBLE:
        final double doubleVal = Double.parseDouble(param);
        pstmt.setDouble(paramIndex, doubleVal);
        break;
      case Types.FLOAT:
      case Types.REAL:
        final float floatVal = Float.parseFloat(param);
        pstmt.setFloat(paramIndex, floatVal);
        break;
      case Types.INTEGER:
      case Types.SMALLINT:
      case Types.TINYINT:
        final int intVal = Integer.parseInt(param);
        pstmt.setInt(paramIndex, intVal);
        break;
      case Types.TIME:
        final java.sql.Time timeVal = java.sql.Time.valueOf(param);
        pstmt.setTime(paramIndex, timeVal);
        break;
      case Types.TIMESTAMP:
        final java.sql.Timestamp timestampVal = java.sql.Timestamp
            .valueOf(param);
        pstmt.setTimestamp(paramIndex, timestampVal);
        break;
      case Types.BINARY:
      case Types.BLOB:
      case Types.LONGVARBINARY:
      case Types.VARBINARY:
        bytes = ClientSharedUtils.fromHexString(param, 0, param.length());
        pstmt.setBytes(paramIndex, bytes);
        break;
      case Types.JAVA_OBJECT:
        bytes = ClientSharedUtils.fromHexString(param, 0, param.length());
        ByteArrayDataInput in = new ByteArrayDataInput();
        in.initialize(bytes, null);
        pstmt.setObject(paramIndex, DataSerializer.readObject(in));
        break;
      default:
        pstmt.setString(paramIndex, param);
        break;
    }
  }
}
 
Example 11
Source File: MemoryQueryResult.java    From shardingsphere with Apache License 2.0 4 votes vote down vote up
private Object getRowValue(final ResultSet resultSet, final int columnIndex) throws SQLException {
    ResultSetMetaData metaData = resultSet.getMetaData();
    switch (metaData.getColumnType(columnIndex)) {
        case Types.BOOLEAN:
            return resultSet.getBoolean(columnIndex);
        case Types.TINYINT:
        case Types.SMALLINT:
            return resultSet.getInt(columnIndex);
        case Types.INTEGER:
            if (metaData.isSigned(columnIndex)) {
                return resultSet.getInt(columnIndex);
            }
            return resultSet.getLong(columnIndex);
        case Types.BIGINT:
            if (metaData.isSigned(columnIndex)) {
                return resultSet.getLong(columnIndex);
            }
            BigDecimal bigDecimal = resultSet.getBigDecimal(columnIndex);
            return bigDecimal == null ? null : bigDecimal.toBigInteger();
        case Types.NUMERIC:
        case Types.DECIMAL:
            return resultSet.getBigDecimal(columnIndex);
        case Types.FLOAT:
        case Types.DOUBLE:
            return resultSet.getDouble(columnIndex);
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            return resultSet.getString(columnIndex);
        case Types.DATE:
            return resultSet.getDate(columnIndex);
        case Types.TIME:
            return resultSet.getTime(columnIndex);
        case Types.TIMESTAMP:
            return resultSet.getTimestamp(columnIndex);
        case Types.CLOB:
            return resultSet.getClob(columnIndex);
        case Types.BLOB:
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            return resultSet.getBlob(columnIndex);
        default:
            return resultSet.getObject(columnIndex);
    }
}
 
Example 12
Source File: CSVWriter.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
private static String getColumnValue(ResultSet rs, int colType, int colIndex)
	throws SQLException, IOException{
	
	String value = "";
	
	switch (colType) {
	case Types.BIT:
		Object bit = rs.getObject(colIndex);
		if (bit != null) {
			value = String.valueOf(bit);
		}
		break;
	case Types.BOOLEAN:
		boolean b = rs.getBoolean(colIndex);
		if (!rs.wasNull()) {
			value = Boolean.valueOf(b).toString();
		}
		break;
	case Types.CLOB:
		Clob c = rs.getClob(colIndex);
		if (c != null) {
			value = read(c);
		}
		break;
	case Types.BIGINT:
	case Types.DECIMAL:
	case Types.DOUBLE:
	case Types.FLOAT:
	case Types.REAL:
	case Types.NUMERIC:
		BigDecimal bd = rs.getBigDecimal(colIndex);
		if (bd != null) {
			value = "" + bd.doubleValue();
		}
		break;
	case Types.INTEGER:
	case Types.TINYINT:
	case Types.SMALLINT:
		int intValue = rs.getInt(colIndex);
		if (!rs.wasNull()) {
			value = "" + intValue;
		}
		break;
	case Types.JAVA_OBJECT:
		Object obj = rs.getObject(colIndex);
		if (obj != null) {
			value = String.valueOf(obj);
		}
		break;
	case Types.DATE:
		java.sql.Date date = rs.getDate(colIndex);
		if (date != null) {
			value = DATE_FORMATTER.format(date);
			;
		}
		break;
	case Types.TIME:
		Time t = rs.getTime(colIndex);
		if (t != null) {
			value = t.toString();
		}
		break;
	case Types.TIMESTAMP:
		Timestamp tstamp = rs.getTimestamp(colIndex);
		if (tstamp != null) {
			value = TIMESTAMP_FORMATTER.format(tstamp);
		}
		break;
	case Types.LONGVARCHAR:
	case Types.VARCHAR:
	case Types.CHAR:
		value = rs.getString(colIndex);
		break;
	default:
		value = "";
	}
	
	if (value == null) {
		value = "";
	}
	
	return value;
	
}
 
Example 13
Source File: ResultSetMetaData.java    From Komondor with GNU General Public License v3.0 4 votes vote down vote up
static String getClassNameForJavaType(int javaType, boolean isUnsigned, int mysqlTypeIfKnown, boolean isBinaryOrBlob, boolean isOpaqueBinary,
        boolean treatYearAsDate) {
    switch (javaType) {
        case Types.BIT:
        case Types.BOOLEAN:
            return "java.lang.Boolean";

        case Types.TINYINT:

            if (isUnsigned) {
                return "java.lang.Integer";
            }

            return "java.lang.Integer";

        case Types.SMALLINT:

            if (isUnsigned) {
                return "java.lang.Integer";
            }

            return "java.lang.Integer";

        case Types.INTEGER:

            if (!isUnsigned || mysqlTypeIfKnown == MysqlDefs.FIELD_TYPE_INT24) {
                return "java.lang.Integer";
            }

            return "java.lang.Long";

        case Types.BIGINT:

            if (!isUnsigned) {
                return "java.lang.Long";
            }

            return "java.math.BigInteger";

        case Types.DECIMAL:
        case Types.NUMERIC:
            return "java.math.BigDecimal";

        case Types.REAL:
            return "java.lang.Float";

        case Types.FLOAT:
        case Types.DOUBLE:
            return "java.lang.Double";

        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            if (!isOpaqueBinary) {
                return "java.lang.String";
            }

            return "[B";

        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:

            if (mysqlTypeIfKnown == MysqlDefs.FIELD_TYPE_GEOMETRY) {
                return "[B";
            } else if (isBinaryOrBlob) {
                return "[B";
            } else {
                return "java.lang.String";
            }

        case Types.DATE:
            return (treatYearAsDate || mysqlTypeIfKnown != MysqlDefs.FIELD_TYPE_YEAR) ? "java.sql.Date" : "java.lang.Short";

        case Types.TIME:
            return "java.sql.Time";

        case Types.TIMESTAMP:
            return "java.sql.Timestamp";

        default:
            return "java.lang.Object";
    }
}
 
Example 14
Source File: SQLTypeMap.java    From Kylin with Apache License 2.0 4 votes vote down vote up
public static Object wrapObject(String value, int sqlType) {
    if (null == value) {
        return null;
    }

    switch (sqlType) {
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        return value;
    case Types.NUMERIC:
    case Types.DECIMAL:
        return new BigDecimal(value);
    case Types.BIT:
        return Boolean.parseBoolean(value);
    case Types.TINYINT:
        return Byte.valueOf(value);
    case Types.SMALLINT:
        return Short.valueOf(value);
    case Types.INTEGER:
        return Integer.parseInt(value);
    case Types.BIGINT:
        return Long.parseLong(value);
    case Types.FLOAT:
        return Float.parseFloat(value);
    case Types.REAL:
    case Types.DOUBLE:
        return Double.parseDouble(value);
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        return value.getBytes();
    case Types.DATE:
        return Date.valueOf(value);
    case Types.TIME:
        return Time.valueOf(value);
    case Types.TIMESTAMP:
        return Timestamp.valueOf(value);
    }

    return value;
}
 
Example 15
Source File: MTypesTranslator.java    From sql-layer with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public TClass typeClassForJDBCType(int jdbcType,
                                   String schemaName, String tableName, String columnName) {
    switch (jdbcType) {
    case Types.BIGINT:
        return MNumeric.BIGINT;
    case Types.BINARY:
    case Types.BIT:
        return MBinary.BINARY;
    case Types.CHAR:
    case Types.NCHAR:
        return MString.CHAR;
    case Types.CLOB:
    case Types.NCLOB:
    case Types.LONGVARCHAR:
    case Types.LONGNVARCHAR:
  //case Types.SQLXML:
        return MString.LONGTEXT;
    case Types.DATE:
        return MDateAndTime.DATE;
    case Types.DECIMAL:
    case Types.NUMERIC:
        return MNumeric.DECIMAL;
    case Types.DOUBLE:
        return MApproximateNumber.DOUBLE;
    case Types.FLOAT:
    case Types.REAL:
        return MApproximateNumber.FLOAT;
    case Types.INTEGER:
        return MNumeric.INT;
    case Types.SMALLINT:
        return MNumeric.SMALLINT;
    case Types.TIME:
        return MDateAndTime.TIME;
    case Types.TIMESTAMP:
        return MDateAndTime.DATETIME; // (Not TIMESTAMP.)
    case Types.TINYINT:
        return MNumeric.TINYINT;
    case Types.VARBINARY:
        return MBinary.VARBINARY;
    case Types.VARCHAR:
    case Types.NVARCHAR:
        return MString.VARCHAR;
    default:
        return super.typeClassForJDBCType(jdbcType, schemaName, tableName, columnName);
    }
}
 
Example 16
Source File: TimeTypeDescriptor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getSqlType() {
	return Types.TIME;
}
 
Example 17
Source File: SQL92.java    From GeoTriples with Apache License 2.0 4 votes vote down vote up
public DataType getDataType(int jdbcType, String name, int size) {
	// TODO: These are in java.sql.Types as of Java 6 but not yet in Java 1.5
	if ("NCHAR".equals(name) || "NVARCHAR".equals(name) || "NCLOB".equals(name)) {
		return new SQLCharacterStringVarying(name, true);
	}

	
	switch (jdbcType) {
	case Types.CHAR:
		return new SQLCharacterString(name, true);

	case Types.VARCHAR:
	case Types.LONGVARCHAR:
	case Types.CLOB:
		return new SQLCharacterStringVarying(name, true);
		
	case Types.BOOLEAN:
		return new SQLBoolean(name);

	case Types.BINARY:
	case Types.VARBINARY:
	case Types.LONGVARBINARY:
	case Types.BLOB:
		return new SQLBinary(name, true);
		
	case Types.BIT:
		return new SQLBit(name);

	case Types.NUMERIC:
	case Types.DECIMAL:
	case Types.TINYINT:
	case Types.SMALLINT:
	case Types.INTEGER:
	case Types.BIGINT:
		return new SQLExactNumeric(name, jdbcType, false);
		
	case Types.REAL:
	case Types.FLOAT:
	case Types.DOUBLE:
		return new SQLApproximateNumeric(name);
	
	case Types.DATE:
		return new SQLDate(name);
		
	case Types.TIME:
		return new SQLTime(name);
		
	case Types.TIMESTAMP:
		return new SQLTimestamp(name);

	case Types.ARRAY:
	case Types.JAVA_OBJECT:
		return new UnsupportedDataType(jdbcType, name);
		
	// TODO: What about the remaining java.sql.Types?
	case Types.DATALINK:
	case Types.DISTINCT:
	case Types.NULL:
	case Types.OTHER:
	case Types.REF:
	}
	
	return null;
}
 
Example 18
Source File: JdbcQuery.java    From opentest with MIT License 4 votes vote down vote up
@Override
public void run() {
    String jdbcUrl = this.readStringArgument("jdbcUrl");
    String user = this.readStringArgument("user", null);
    String password = this.readStringArgument("password", null);
    String sql = this.readStringArgument("sql");

    try {
        Connection conn;

        if (user != null && password != null) {
            conn = DriverManager.getConnection(jdbcUrl, user, password);
        } else {
            conn = DriverManager.getConnection(jdbcUrl);
        }

        Statement statement = conn.createStatement();
        ResultSet resultSet = statement.executeQuery(sql);
        ResultSetMetaData rsMetaData = resultSet.getMetaData();

        List<Map<String, Object>> rows = new ArrayList<>();
        int columnCount = rsMetaData.getColumnCount();
        while (resultSet.next()) {
            Map<String, Object> row = new HashMap<>();
            for (int columnNo = 1; columnNo <= columnCount; columnNo++) {
                switch (rsMetaData.getColumnType(columnNo)) {
                    case Types.DATE:
                    case Types.TIME:
                    case Types.TIME_WITH_TIMEZONE:
                    case Types.TIMESTAMP:
                    case Types.TIMESTAMP_WITH_TIMEZONE:
                        row.put(rsMetaData.getColumnName(columnNo), resultSet.getObject(columnNo).toString());
                        break;
                    default:
                        row.put(rsMetaData.getColumnName(columnNo), resultSet.getObject(columnNo));
                }
            }
            rows.add(row);
        }
        resultSet.close();

        this.writeOutput("rows", rows);
        this.writeOutput("rowCount", rows.size());
    } catch (SQLException ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 19
Source File: JDBC42ObjectConverter.java    From jaybird with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public boolean setObject(final FBField field, final Object object) throws SQLException {
    if (object instanceof LocalDate) {
        switch (field.requiredType) {
        case Types.DATE:
            LocalDate localDate = (LocalDate) object;
            field.setFieldData(field.getDatatypeCoder().encodeLocalDate(
                    localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth()));
            return true;
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            field.setString(object.toString());
            return true;
        }
    } else if (object instanceof LocalTime) {
        switch (field.requiredType) {
        case Types.TIME:
            LocalTime localTime = (LocalTime) object;
            field.setFieldData(field.getDatatypeCoder().encodeLocalTime(
                    localTime.getHour(), localTime.getMinute(), localTime.getSecond(), localTime.getNano()));
            return true;
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            field.setString(object.toString());
            return true;
        }
    } else if (object instanceof LocalDateTime) {
        LocalDateTime localDateTime = (LocalDateTime) object;
        switch (field.requiredType) {
        case Types.DATE:
            field.setFieldData(field.getDatatypeCoder().encodeLocalDate(
                    localDateTime.getYear(), localDateTime.getMonthValue(), localDateTime.getDayOfMonth()));
            return true;
        case Types.TIME:
            field.setFieldData(field.getDatatypeCoder().encodeLocalTime(
                    localDateTime.getHour(), localDateTime.getMinute(), localDateTime.getSecond(),
                    localDateTime.getNano()));
            return true;
        case Types.TIMESTAMP:
            field.setFieldData(field.getDatatypeCoder().encodeLocalDateTime(
                    localDateTime.getYear(), localDateTime.getMonthValue(), localDateTime.getDayOfMonth(),
                    localDateTime.getHour(), localDateTime.getMinute(), localDateTime.getSecond(),
                    localDateTime.getNano()));
            return true;
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            field.setString(object.toString());
            return true;
        }
    } else if (object instanceof OffsetTime || object instanceof OffsetDateTime) {
        switch (field.requiredType) {
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            field.setString(object.toString());
            return true;
        }
    }
    return false;
}
 
Example 20
Source File: TimeTypeCompiler.java    From spliceengine with GNU Affero General Public License v3.0 1 votes vote down vote up
/**
 * User types are storable into other user types that they
 * are assignable to. The other type must be a subclass of
 * this type, or implement this type as one of its interfaces.
 *
 * Built-in types are also storable into user types when the built-in
 * type's corresponding Java type is assignable to the user type.
 *
 * @param otherType the type of the instance to store into this type.
 * @param cf		A ClassFactory
 * @return true if otherType is storable into this type, else false.
 */
public boolean storable(TypeId otherType, ClassFactory cf) {
       int otherJDBCTypeId = otherType.getJDBCTypeId();

       return otherJDBCTypeId == Types.TIME || (otherJDBCTypeId == Types.CHAR) || (otherJDBCTypeId == Types.VARCHAR) || (otherJDBCTypeId == Types.TIMESTAMP) || cf.getClassInspector().assignableTo(otherType.getCorrespondingJavaTypeName(), "java.sql.Time");

   }