Java Code Examples for java.sql.Types#LONGNVARCHAR

The following examples show how to use java.sql.Types#LONGNVARCHAR . 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: SQLTypeUtil.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Returns if the given data type is character type or not.
 *
 * @param type the type from java.sql.Types
 * @return true if the given type is character type; false otherwise
 */
static public boolean isCharacter(int type) {
    switch (type) {
        case Types.BINARY:
        case Types.CHAR:
        case Types.LONGVARCHAR:
        case Types.VARCHAR:
        case Types.VARBINARY:
        case Types.NCHAR:
        case Types.NVARCHAR:
        case Types.LONGNVARCHAR:
            return true;
    }

    return false;
}
 
Example 2
Source File: PostgreSQLServerHelper.java    From dbtransfer with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public int translateType( int type ) 
{
	int pType = type;
	switch ( type ) 
	{
		case Types.NCHAR:
			pType = Types.CHAR;
			break;	
		case Types.NVARCHAR:
			pType = Types.VARCHAR;
			break;
		case Types.LONGNVARCHAR:
			pType = Types.LONGVARCHAR;
		case Types.BOOLEAN:
			pType = Types.BIT;
		default:
			break;
	}
	return pType;
}
 
Example 3
Source File: DBTablePrinter.java    From salesforce-jdbc with MIT License 5 votes vote down vote up
/**
 * Takes a generic SQL type and returns the category this type
 * belongs to. Types are categorized according to print formatting
 * needs:
 * <p>
 * Integers should not be truncated so column widths should
 * be adjusted without a column width limit. Text columns should be
 * left justified and can be truncated to a max. column width etc...</p>
 * <p>
 * See also: <a target="_blank"
 * href="http://docs.oracle.com/javase/8/docs/api/java/sql/Types.html">
 * java.sql.Types</a>
 *
 * @param type Generic SQL type
 * @return The category this type belongs to
 */
private static int whichCategory(int type) {
    switch (type) {
        case Types.BIGINT:
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
            return CATEGORY_INTEGER;

        case Types.REAL:
        case Types.DOUBLE:
        case Types.DECIMAL:
            return CATEGORY_DOUBLE;

        case Types.DATE:
        case Types.TIME:
        case Types.TIME_WITH_TIMEZONE:
        case Types.TIMESTAMP:
        case Types.TIMESTAMP_WITH_TIMEZONE:
            return CATEGORY_DATETIME;

        case Types.BOOLEAN:
            return CATEGORY_BOOLEAN;

        case Types.VARCHAR:
        case Types.NVARCHAR:
        case Types.LONGVARCHAR:
        case Types.LONGNVARCHAR:
        case Types.CHAR:
        case Types.NCHAR:
            return CATEGORY_STRING;

        default:
            return CATEGORY_OTHER;
    }
}
 
Example 4
Source File: DataTypes.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
/**
  * throws runtime exception if the type conversion fails.
  * @param sqlType
  * @return
  */
 public static byte SQLTypeToGSNTypeSimplified(int sqlType) {
  if (sqlType == Types.BIGINT || sqlType == Types.SMALLINT || sqlType == Types.DOUBLE || sqlType==Types.INTEGER || sqlType == Types.DECIMAL||sqlType == Types.REAL || sqlType == Types.FLOAT|| sqlType == Types.NUMERIC )
	return  DataTypes.DOUBLE;
else if (sqlType == Types.VARCHAR || sqlType == Types.CHAR|| sqlType == Types.LONGNVARCHAR || sqlType == Types.LONGVARCHAR || sqlType== Types.NCHAR )
	return  DataTypes.VARCHAR;
else if (sqlType == Types.BINARY || sqlType == Types.BLOB|| sqlType == Types.VARBINARY )
	return  DataTypes.BINARY;
  throw new RuntimeException("Can't convert SQL type id of: "+sqlType+ " to GSN type id.");
 }
 
Example 5
Source File: RowSetMetaDataTests.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@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"}

    };

}
 
Example 6
Source File: DB2ColumnMetadataReaderTest.java    From virtual-schemas with MIT License 5 votes vote down vote up
@ValueSource(ints = { Types.VARCHAR, Types.NVARCHAR, Types.LONGNVARCHAR, Types.CHAR, Types.NCHAR,
        Types.LONGNVARCHAR })
@ParameterizedTest
void testMapJdbcVarcharSizeLesserThanExasolMaxVarcharSize(final int type) {
    final JdbcTypeDescription jdbcTypeDescription = new JdbcTypeDescription(type, 0, 10, 0, "");
    assertThat(this.db2ColumnMetadataReader.mapJdbcType(jdbcTypeDescription),
            equalTo(DataType.createVarChar(10, DataType.ExaCharset.UTF8)));
}
 
Example 7
Source File: VerticaSpecific.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public boolean isJetelTypeConvertible2sql(int sqlType, DataFieldMetadata field) {
	if ((sqlType == Types.OTHER) || isIntervalType(sqlType)) {
		// Vertica interval types and UUID
		return field.getDataType() == DataFieldType.STRING;
	}
	switch (field.getDataType()) {
		case BOOLEAN:
			// BOOLEAN type is returned as Types.BIT
			return (sqlType == Types.BIT) || super.isJetelTypeConvertible2sql(sqlType, field);
		case INTEGER:
		case LONG:
			return (sqlType == Types.BIGINT) || super.isJetelTypeConvertible2sql(sqlType, field);
		case DECIMAL:
			return (sqlType == Types.NUMERIC) || super.isJetelTypeConvertible2sql(sqlType, field);
		case BYTE: 
		case CBYTE:
			return (sqlType == Types.LONGVARBINARY) || super.isJetelTypeConvertible2sql(sqlType, field);
		case STRING:
			switch (sqlType) {
			case Types.LONGVARCHAR:
			case Types.LONGNVARCHAR:
				return true;
			}
		default:
			return super.isJetelTypeConvertible2sql(sqlType, field);
	}
}
 
Example 8
Source File: ConnManager.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 5 votes vote down vote up
/**
 * Determine if a column is char or a char-variant type.
 * @return true if column type is CHAR, VARCHAR, LONGVARCHAR
 * or their N version. These are used to store strings.
 */
public boolean isCharColumn(int columnType) {
  return (columnType == Types.VARCHAR)
      || (columnType == Types.NVARCHAR)
      || (columnType == Types.CHAR)
      || (columnType == Types.NCHAR)
      || (columnType == Types.LONGVARCHAR)
      || (columnType == Types.LONGNVARCHAR);
}
 
Example 9
Source File: Converters.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Get {@link GFXDType} for given JDBC {@link Types}.
 */
public static GFXDType getThriftSQLType(int jdbcType) {
  switch (jdbcType) {
    case Types.ARRAY:
      return GFXDType.ARRAY;
    case Types.BIGINT:
      return GFXDType.BIGINT;
    case Types.BINARY:
      return GFXDType.BINARY;
    case Types.BIT:
      return GFXDType.BOOLEAN;
    case Types.BLOB:
      return GFXDType.BLOB;
    case Types.BOOLEAN:
      return GFXDType.BOOLEAN;
    case Types.CHAR:
      return GFXDType.CHAR;
    case Types.CLOB:
      return GFXDType.CLOB;
    case Types.DATALINK:
      return GFXDType.DATALINK;
    case Types.DATE:
      return GFXDType.DATE;
    case Types.DECIMAL:
      return GFXDType.DECIMAL;
    case Types.DISTINCT:
      return GFXDType.DISTINCT;
    case Types.DOUBLE:
      return GFXDType.DOUBLE;
    case Types.FLOAT:
      return GFXDType.FLOAT;
    case Types.INTEGER:
      return GFXDType.INTEGER;
    case Types.JAVA_OBJECT:
      return GFXDType.JAVA_OBJECT;
    case TYPE_JSON_OBJECT:
      return GFXDType.JSON_OBJECT;
    case Types.LONGNVARCHAR:
      return GFXDType.LONGNVARCHAR;
    case Types.LONGVARBINARY:
      return GFXDType.LONGVARBINARY;
    case Types.LONGVARCHAR:
      return GFXDType.LONGVARCHAR;
    case Types.NCHAR:
      return GFXDType.NCHAR;
    case Types.NCLOB:
      return GFXDType.NCLOB;
    case Types.NULL:
      return GFXDType.NULLTYPE;
    case Types.NUMERIC:
      return GFXDType.DECIMAL;
    case Types.NVARCHAR:
      return GFXDType.NVARCHAR;
    case Types.OTHER:
      return GFXDType.OTHER;
    case TYPE_PDX_OBJECT:
      return GFXDType.PDX_OBJECT;
    case Types.REAL:
      return GFXDType.REAL;
    case Types.REF:
      return GFXDType.REF;
    case Types.ROWID:
      return GFXDType.ROWID;
    case Types.SMALLINT:
      return GFXDType.SMALLINT;
    case Types.SQLXML:
      return GFXDType.SQLXML;
    case Types.STRUCT:
      return GFXDType.STRUCT;
    case Types.TIME:
      return GFXDType.TIME;
    case Types.TIMESTAMP:
      return GFXDType.TIMESTAMP;
    case Types.TINYINT:
      return GFXDType.TINYINT;
    case Types.VARBINARY:
      return GFXDType.VARBINARY;
    case Types.VARCHAR:
      return GFXDType.VARCHAR;
    default:
      return GFXDType.OTHER;
  }
}
 
Example 10
Source File: AbstractCursor.java    From calcite-avatica with Apache License 2.0 4 votes vote down vote up
private Object convertValue() throws SQLException {
  switch (componentType.id) {
  case Types.BOOLEAN:
  case Types.BIT:
    return componentAccessor.getBoolean();
  case Types.TINYINT:
    return componentAccessor.getByte();
  case Types.SMALLINT:
    return componentAccessor.getShort();
  case Types.INTEGER:
    return componentAccessor.getInt();
  case Types.BIGINT:
    return componentAccessor.getLong();
  case Types.FLOAT:
    return componentAccessor.getFloat();
  case Types.DOUBLE:
    return componentAccessor.getDouble();
  case Types.ARRAY:
    return componentAccessor.getArray();
  case Types.CHAR:
  case Types.VARCHAR:
  case Types.LONGVARCHAR:
  case Types.NCHAR:
  case Types.LONGNVARCHAR:
    return componentAccessor.getString();
  case Types.BINARY:
  case Types.VARBINARY:
  case Types.LONGVARBINARY:
    return componentAccessor.getBytes();
  case Types.DECIMAL:
    return componentAccessor.getBigDecimal();
  case Types.DATE:
  case Types.TIME:
  case Types.TIMESTAMP:
  case Types.STRUCT:
  case Types.JAVA_OBJECT:
    return componentAccessor.getObject();
  default:
    throw new IllegalStateException("Unhandled ARRAY component type: " + componentType.rep
        + ", id: " + componentType.id);
  }
}
 
Example 11
Source File: ParseUtil.java    From datacollector with Apache License 2.0 4 votes vote down vote up
public static Field generateField(
    String column,
    String columnValue,
    int columnType,
    DateTimeColumnHandler dateTimeColumnHandler
) throws StageException {
  Field field;
  // 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 (columnType) {
    case Types.BIGINT:
      field = Field.create(Field.Type.LONG, columnValue);
      break;
    case Types.BINARY:
    case Types.LONGVARBINARY:
    case Types.VARBINARY:
      field = Field.create(Field.Type.BYTE_ARRAY, RawTypeHandler.parseRaw(column, columnValue, columnType));
      break;
    case Types.BIT:
    case Types.BOOLEAN:
      field = Field.create(Field.Type.BOOLEAN, columnValue);
      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, columnValue);
      break;
    case Types.DECIMAL:
    case Types.NUMERIC:
      field = Field.create(Field.Type.DECIMAL, columnValue);
      break;
    case Types.DOUBLE:
      field = Field.create(Field.Type.DOUBLE, columnValue);
      break;
    case Types.FLOAT:
    case Types.REAL:
      field = Field.create(Field.Type.FLOAT, columnValue);
      break;
    case Types.INTEGER:
      field = Field.create(Field.Type.INTEGER, columnValue);
      break;
    case Types.SMALLINT:
    case Types.TINYINT:
      field = Field.create(Field.Type.SHORT, columnValue);
      break;
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
      field = dateTimeColumnHandler.getDateTimeStampField(column, columnValue, columnType);
      break;
    case Types.TIMESTAMP_WITH_TIMEZONE:
    case TIMESTAMP_TZ_TYPE:
      field = dateTimeColumnHandler.getTimestampWithTimezoneField(columnValue);
      break;
    case TIMESTAMP_LTZ_TYPE:
      field = dateTimeColumnHandler.getTimestampWithLocalTimezone(columnValue);
      break;
    case Types.ROWID:
    case Types.CLOB:
    case Types.NCLOB:
    case Types.BLOB:
    case Types.ARRAY:
    case Types.DATALINK:
    case Types.DISTINCT:
    case Types.JAVA_OBJECT:
    case Types.NULL:
    case Types.OTHER:
    case Types.REF:
    case Types.REF_CURSOR:
    case Types.SQLXML:
    case Types.STRUCT:
    case Types.TIME_WITH_TIMEZONE:
    default:
      throw new UnsupportedFieldTypeException(column, columnValue, columnType);
  }
  return field;
}
 
Example 12
Source File: ResultSetRecordSet.java    From nifi with Apache License 2.0 4 votes vote down vote up
private static RecordFieldType getFieldType(final int sqlType, final String valueClassName) {
    switch (sqlType) {
        case Types.BIGINT:
        case Types.ROWID:
            return RecordFieldType.LONG;
        case Types.BIT:
        case Types.BOOLEAN:
            return RecordFieldType.BOOLEAN;
        case Types.CHAR:
            return RecordFieldType.CHAR;
        case Types.DATE:
            return RecordFieldType.DATE;
        case Types.NUMERIC:
        case Types.DECIMAL:
            return RecordFieldType.DECIMAL;
        case Types.DOUBLE:
        case Types.REAL:
            return RecordFieldType.DOUBLE;
        case Types.FLOAT:
            return RecordFieldType.FLOAT;
        case Types.INTEGER:
            return RecordFieldType.INT;
        case Types.SMALLINT:
            return RecordFieldType.SHORT;
        case Types.TINYINT:
            return RecordFieldType.BYTE;
        case Types.LONGNVARCHAR:
        case Types.LONGVARCHAR:
        case Types.NCHAR:
        case Types.NULL:
        case Types.NVARCHAR:
        case Types.VARCHAR:
            return RecordFieldType.STRING;
        case Types.OTHER:
        case Types.JAVA_OBJECT:
            if (STRING_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.STRING;
            }
            if (INT_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.INT;
            }
            if (LONG_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.LONG;
            }
            if (DATE_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.DATE;
            }
            if (FLOAT_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.FLOAT;
            }
            if (DOUBLE_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.DOUBLE;
            }
            if (BIGDECIMAL_CLASS_NAME.equals(valueClassName)) {
                return RecordFieldType.DECIMAL;
            }

            return RecordFieldType.RECORD;
        case Types.TIME:
        case Types.TIME_WITH_TIMEZONE:
            return RecordFieldType.TIME;
        case Types.TIMESTAMP:
        case Types.TIMESTAMP_WITH_TIMEZONE:
        case -101: // Oracle's TIMESTAMP WITH TIME ZONE
        case -102: // Oracle's TIMESTAMP WITH LOCAL TIME ZONE
            return RecordFieldType.TIMESTAMP;
    }

    return RecordFieldType.STRING;
}
 
Example 13
Source File: AbstractHive_1_1QLProcessor.java    From nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Determines how to map the given value to the appropriate JDBC data jdbcType and sets the parameter on the
 * provided PreparedStatement
 *
 * @param stmt           the PreparedStatement to set the parameter on
 * @param attrName       the name of the attribute that the parameter is coming from - for logging purposes
 * @param parameterIndex the index of the HiveQL parameter to set
 * @param parameterValue the value of the HiveQL parameter to set
 * @param jdbcType       the JDBC Type of the HiveQL parameter to set
 * @throws SQLException if the PreparedStatement throws a SQLException when calling the appropriate setter
 */
protected void setParameter(final PreparedStatement stmt, final String attrName, final int parameterIndex, final String parameterValue, final int jdbcType) throws SQLException {
    if (parameterValue == null) {
        stmt.setNull(parameterIndex, jdbcType);
    } else {
        try {
            switch (jdbcType) {
                case Types.BIT:
                case Types.BOOLEAN:
                    stmt.setBoolean(parameterIndex, Boolean.parseBoolean(parameterValue));
                    break;
                case Types.TINYINT:
                    stmt.setByte(parameterIndex, Byte.parseByte(parameterValue));
                    break;
                case Types.SMALLINT:
                    stmt.setShort(parameterIndex, Short.parseShort(parameterValue));
                    break;
                case Types.INTEGER:
                    stmt.setInt(parameterIndex, Integer.parseInt(parameterValue));
                    break;
                case Types.BIGINT:
                    stmt.setLong(parameterIndex, Long.parseLong(parameterValue));
                    break;
                case Types.REAL:
                    stmt.setFloat(parameterIndex, Float.parseFloat(parameterValue));
                    break;
                case Types.FLOAT:
                case Types.DOUBLE:
                    stmt.setDouble(parameterIndex, Double.parseDouble(parameterValue));
                    break;
                case Types.DECIMAL:
                case Types.NUMERIC:
                    stmt.setBigDecimal(parameterIndex, new BigDecimal(parameterValue));
                    break;
                case Types.DATE:
                    stmt.setDate(parameterIndex, new Date(Long.parseLong(parameterValue)));
                    break;
                case Types.TIME:
                    stmt.setTime(parameterIndex, new Time(Long.parseLong(parameterValue)));
                    break;
                case Types.TIMESTAMP:
                    stmt.setTimestamp(parameterIndex, new Timestamp(Long.parseLong(parameterValue)));
                    break;
                case Types.CHAR:
                case Types.VARCHAR:
                case Types.LONGNVARCHAR:
                case Types.LONGVARCHAR:
                    stmt.setString(parameterIndex, parameterValue);
                    break;
                default:
                    stmt.setObject(parameterIndex, parameterValue, jdbcType);
                    break;
            }
        } catch (SQLException e) {
            // Log which attribute/parameter had an error, then rethrow to be handled at the top level
            getLogger().error("Error setting parameter {} to value from {} ({})", new Object[]{parameterIndex, attrName, parameterValue}, e);
            throw e;
        }
    }
}
 
Example 14
Source File: Converters.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Get {@link GFXDType} for given JDBC {@link Types}.
 */
public static GFXDType getThriftSQLType(int jdbcType) {
  switch (jdbcType) {
    case Types.ARRAY:
      return GFXDType.ARRAY;
    case Types.BIGINT:
      return GFXDType.BIGINT;
    case Types.BINARY:
      return GFXDType.BINARY;
    case Types.BIT:
      return GFXDType.BOOLEAN;
    case Types.BLOB:
      return GFXDType.BLOB;
    case Types.BOOLEAN:
      return GFXDType.BOOLEAN;
    case Types.CHAR:
      return GFXDType.CHAR;
    case Types.CLOB:
      return GFXDType.CLOB;
    case Types.DATALINK:
      return GFXDType.DATALINK;
    case Types.DATE:
      return GFXDType.DATE;
    case Types.DECIMAL:
      return GFXDType.DECIMAL;
    case Types.DISTINCT:
      return GFXDType.DISTINCT;
    case Types.DOUBLE:
      return GFXDType.DOUBLE;
    case Types.FLOAT:
      return GFXDType.FLOAT;
    case Types.INTEGER:
      return GFXDType.INTEGER;
    case Types.JAVA_OBJECT:
      return GFXDType.JAVA_OBJECT;
    case TYPE_JSON_OBJECT:
      return GFXDType.JSON_OBJECT;
    case Types.LONGNVARCHAR:
      return GFXDType.LONGNVARCHAR;
    case Types.LONGVARBINARY:
      return GFXDType.LONGVARBINARY;
    case Types.LONGVARCHAR:
      return GFXDType.LONGVARCHAR;
    case Types.NCHAR:
      return GFXDType.NCHAR;
    case Types.NCLOB:
      return GFXDType.NCLOB;
    case Types.NULL:
      return GFXDType.NULLTYPE;
    case Types.NUMERIC:
      return GFXDType.DECIMAL;
    case Types.NVARCHAR:
      return GFXDType.NVARCHAR;
    case Types.OTHER:
      return GFXDType.OTHER;
    case TYPE_PDX_OBJECT:
      return GFXDType.PDX_OBJECT;
    case Types.REAL:
      return GFXDType.REAL;
    case Types.REF:
      return GFXDType.REF;
    case Types.ROWID:
      return GFXDType.ROWID;
    case Types.SMALLINT:
      return GFXDType.SMALLINT;
    case Types.SQLXML:
      return GFXDType.SQLXML;
    case Types.STRUCT:
      return GFXDType.STRUCT;
    case Types.TIME:
      return GFXDType.TIME;
    case Types.TIMESTAMP:
      return GFXDType.TIMESTAMP;
    case Types.TINYINT:
      return GFXDType.TINYINT;
    case Types.VARBINARY:
      return GFXDType.VARBINARY;
    case Types.VARCHAR:
      return GFXDType.VARCHAR;
    default:
      return GFXDType.OTHER;
  }
}
 
Example 15
Source File: SqlTypesUtils.java    From sqoop-on-spark with Apache License 2.0 4 votes vote down vote up
/**
 * Convert given java.sql.Types number into internal data type.
 *
 * @param sqlType java.sql.Types constant
 * @param columnName column name
 *
 * @return Concrete Column implementation
 */
public static Column sqlTypeToSchemaType(int sqlType, String columnName, int precision, int scale) {
  switch (sqlType) {
    case Types.SMALLINT:
    case Types.TINYINT:
      // only supports signed values
      return new FixedPoint(columnName, 2L, true);
    case Types.INTEGER:
      // only supports signed values
      return new FixedPoint(columnName, 4L, true);
    case Types.BIGINT:
      return new FixedPoint(columnName, 8L, true);

    case Types.CLOB:
    case Types.VARCHAR:
    case Types.CHAR:
    case Types.LONGVARCHAR:
    case Types.NVARCHAR:
    case Types.NCHAR:
    case Types.LONGNVARCHAR:
      return new Text(columnName);

    case Types.DATE:
      return new Date(columnName);

    case Types.TIME:
      return new Time(columnName, true);

    case Types.TIMESTAMP:
      return new DateTime(columnName, true, false);

    case Types.FLOAT:
    case Types.REAL:
      return new FloatingPoint(columnName, 4L);
    case Types.DOUBLE:
      return new FloatingPoint(columnName, 8L);

    case Types.NUMERIC:
    case Types.DECIMAL:
      return new Decimal(columnName, precision, scale);

    case Types.BIT:
    case Types.BOOLEAN:
      return new Bit(columnName);

    case Types.BINARY:
    case Types.VARBINARY:
    case Types.BLOB:
    case Types.LONGVARBINARY:
      return new Binary(columnName);

    default:
      return new Unknown(columnName,(long)sqlType);
  }
}
 
Example 16
Source File: AbstractHiveQLProcessor.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Determines how to map the given value to the appropriate JDBC data jdbcType and sets the parameter on the
 * provided PreparedStatement
 *
 * @param stmt           the PreparedStatement to set the parameter on
 * @param attrName       the name of the attribute that the parameter is coming from - for logging purposes
 * @param parameterIndex the index of the HiveQL parameter to set
 * @param parameterValue the value of the HiveQL parameter to set
 * @param jdbcType       the JDBC Type of the HiveQL parameter to set
 * @throws SQLException if the PreparedStatement throws a SQLException when calling the appropriate setter
 */
protected void setParameter(final PreparedStatement stmt, final String attrName, final int parameterIndex, final String parameterValue, final int jdbcType) throws SQLException {
    if (parameterValue == null) {
        stmt.setNull(parameterIndex, jdbcType);
    } else {
        try {
            switch (jdbcType) {
                case Types.BIT:
                case Types.BOOLEAN:
                    stmt.setBoolean(parameterIndex, Boolean.parseBoolean(parameterValue));
                    break;
                case Types.TINYINT:
                    stmt.setByte(parameterIndex, Byte.parseByte(parameterValue));
                    break;
                case Types.SMALLINT:
                    stmt.setShort(parameterIndex, Short.parseShort(parameterValue));
                    break;
                case Types.INTEGER:
                    stmt.setInt(parameterIndex, Integer.parseInt(parameterValue));
                    break;
                case Types.BIGINT:
                    stmt.setLong(parameterIndex, Long.parseLong(parameterValue));
                    break;
                case Types.REAL:
                    stmt.setFloat(parameterIndex, Float.parseFloat(parameterValue));
                    break;
                case Types.FLOAT:
                case Types.DOUBLE:
                    stmt.setDouble(parameterIndex, Double.parseDouble(parameterValue));
                    break;
                case Types.DECIMAL:
                case Types.NUMERIC:
                    stmt.setBigDecimal(parameterIndex, new BigDecimal(parameterValue));
                    break;
                case Types.DATE:
                    stmt.setDate(parameterIndex, new Date(Long.parseLong(parameterValue)));
                    break;
                case Types.TIME:
                    stmt.setTime(parameterIndex, new Time(Long.parseLong(parameterValue)));
                    break;
                case Types.TIMESTAMP:
                    stmt.setTimestamp(parameterIndex, new Timestamp(Long.parseLong(parameterValue)));
                    break;
                case Types.CHAR:
                case Types.VARCHAR:
                case Types.LONGNVARCHAR:
                case Types.LONGVARCHAR:
                    stmt.setString(parameterIndex, parameterValue);
                    break;
                default:
                    stmt.setObject(parameterIndex, parameterValue, jdbcType);
                    break;
            }
        } catch (SQLException e) {
            // Log which attribute/parameter had an error, then rethrow to be handled at the top level
            getLogger().error("Error setting parameter {} to value from {} ({})", new Object[]{parameterIndex, attrName, parameterValue}, e);
            throw e;
        }
    }
}
 
Example 17
Source File: JdbcTypeHelper.java    From SimpleFlatMapper with MIT License 4 votes vote down vote up
public static Class<?> toJavaType(int sqlType, Type propertyType) {
    switch (sqlType) {
        case Types.ARRAY: return Array.class;
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGNVARCHAR:
            return String.class;
        case Types.NUMERIC:
        case Types.DECIMAL:
            return BigDecimal.class;
        case Types.BIT:
            return boolean.class;
        case Types.TINYINT:
            return byte.class;
        case Types.SMALLINT:
            return short.class;
        case Types.INTEGER:
            return int.class;
        case Types.BIGINT:
            return long.class;
        case Types.REAL:
            return float.class;
        case Types.FLOAT:
        case Types.DOUBLE:
            return double.class;
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            return byte[].class;
        case Types.DATE:
            return Date.class;
        case Types.TIME:
            return Time.class;
        case Types.TIMESTAMP:
            return Timestamp.class;
        case Types.CLOB:
            return Clob.class;
        case Types.BLOB:
            return Blob.class;
        case Types.STRUCT:
            return Struct.class;
        case Types.REF:
            return Ref.class;

        //IFJAVA8_START
        case Types.TIME_WITH_TIMEZONE:
            return OffsetTime.class;
        case Types.TIMESTAMP_WITH_TIMEZONE:
            return OffsetDateTime.class;
        //IFJAVA8_END

    }

    Class<?> defaultSqlType = javaTypeToSqlType.get(TypeHelper.toClass(propertyType).getName());
    if (defaultSqlType != null) {
        return defaultSqlType;
    }

    return Object.class;
}
 
Example 18
Source File: KamiQuery.java    From kamike.divide with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void fillResultTypes(ResultSet rs) throws SQLException {
    ResultSetMetaData rsmd = rs.getMetaData();

    for (int i = 1; i <= rsmd.getColumnCount(); i++) {
        int type = rsmd.getColumnType(i);
        String name = rsmd.getColumnName(i);
        switch (type) {
            case Types.BIGINT:
                types.add(GenericType.Long);
                break;
            case Types.BIT:
            case Types.BOOLEAN:
            case Types.INTEGER:
            case Types.TINYINT:
            case Types.SMALLINT:
                types.add(GenericType.Int);
                break;
            case Types.CHAR:
            case Types.CLOB:
            case Types.LONGNVARCHAR:
            case Types.LONGVARCHAR:
            case Types.NCHAR:
            case Types.NCLOB:
            case Types.VARCHAR:
                types.add(GenericType.String);
                break;
            case Types.DATE:
            case Types.TIME:
            case Types.TIMESTAMP:
                types.add(GenericType.Timestamp);
                break;
            case Types.DECIMAL:
            case Types.DOUBLE:
            case Types.FLOAT:
            case Types.NUMERIC:
                types.add(GenericType.Double);
            default:
                types.add(GenericType.String);
                break;
        }

    }

}
 
Example 19
Source File: PrestoPreparedStatement.java    From presto with Apache License 2.0 4 votes vote down vote up
private static String typedNull(int targetSqlType)
        throws SQLException
{
    switch (targetSqlType) {
        case Types.BOOLEAN:
        case Types.BIT:
            return typedNull("BOOLEAN");
        case Types.TINYINT:
            return typedNull("TINYINT");
        case Types.SMALLINT:
            return typedNull("SMALLINT");
        case Types.INTEGER:
            return typedNull("INTEGER");
        case Types.BIGINT:
            return typedNull("BIGINT");
        case Types.FLOAT:
        case Types.REAL:
            return typedNull("REAL");
        case Types.DOUBLE:
            return typedNull("DOUBLE");
        case Types.DECIMAL:
        case Types.NUMERIC:
            return typedNull("DECIMAL");
        case Types.CHAR:
        case Types.NCHAR:
            return typedNull("CHAR");
        case Types.VARCHAR:
        case Types.NVARCHAR:
        case Types.LONGVARCHAR:
        case Types.LONGNVARCHAR:
        case Types.CLOB:
        case Types.NCLOB:
            return typedNull("VARCHAR");
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
        case Types.BLOB:
            return typedNull("VARBINARY");
        case Types.DATE:
            return typedNull("DATE");
        case Types.TIME:
            return typedNull("TIME");
        case Types.TIMESTAMP:
            return typedNull("TIMESTAMP");
        // TODO Types.TIME_WITH_TIMEZONE
        // TODO Types.TIMESTAMP_WITH_TIMEZONE
        case Types.NULL:
            return "NULL";
    }
    throw new SQLException("Unsupported target SQL type: " + targetSqlType);
}
 
Example 20
Source File: StandardColumnMappings.java    From presto with Apache License 2.0 4 votes vote down vote up
public static Optional<ColumnMapping> jdbcTypeToPrestoType(ConnectorSession session, JdbcTypeHandle type)
{
    int columnSize = type.getColumnSize();
    switch (type.getJdbcType()) {
        case Types.BIT:
        case Types.BOOLEAN:
            return Optional.of(booleanColumnMapping());

        case Types.TINYINT:
            return Optional.of(tinyintColumnMapping());

        case Types.SMALLINT:
            return Optional.of(smallintColumnMapping());

        case Types.INTEGER:
            return Optional.of(integerColumnMapping());

        case Types.BIGINT:
            return Optional.of(bigintColumnMapping());

        case Types.REAL:
            return Optional.of(realColumnMapping());

        case Types.FLOAT:
        case Types.DOUBLE:
            return Optional.of(doubleColumnMapping());

        case Types.NUMERIC:
        case Types.DECIMAL:
            int decimalDigits = type.getDecimalDigits();
            int precision = columnSize + max(-decimalDigits, 0); // Map decimal(p, -s) (negative scale) to decimal(p+s, 0).
            if (precision > Decimals.MAX_PRECISION) {
                return Optional.empty();
            }
            return Optional.of(decimalColumnMapping(createDecimalType(precision, max(decimalDigits, 0)), UNNECESSARY));

        case Types.CHAR:
        case Types.NCHAR:
            // TODO this is wrong, we're going to construct malformed Slice representation if source > charLength
            int charLength = min(columnSize, CharType.MAX_LENGTH);
            return Optional.of(charColumnMapping(createCharType(charLength)));

        case Types.VARCHAR:
        case Types.NVARCHAR:
        case Types.LONGVARCHAR:
        case Types.LONGNVARCHAR:
            if (columnSize > VarcharType.MAX_LENGTH) {
                return Optional.of(varcharColumnMapping(createUnboundedVarcharType()));
            }
            return Optional.of(varcharColumnMapping(createVarcharType(columnSize)));

        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            return Optional.of(varbinaryColumnMapping());

        case Types.DATE:
            return Optional.of(dateColumnMapping());

        case Types.TIME:
            // TODO default to `timeColumnMapping`
            return Optional.of(timeColumnMappingUsingSqlTime(session));

        case Types.TIMESTAMP:
            // TODO default to `timestampColumnMapping`
            return Optional.of(timestampColumnMappingUsingSqlTimestamp(session));
    }
    return Optional.empty();
}