Java Code Examples for java.sql.Types#VARBINARY

The following examples show how to use java.sql.Types#VARBINARY . 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: Field.java    From r-course with MIT License 6 votes vote down vote up
/**
 * Used by prepared statements to re-use result set data conversion methods
 * when generating bound parmeter retrieval instance for statement
 * interceptors.
 * 
 * @param tableName
 *            not used
 * @param columnName
 *            not used
 * @param charsetIndex
 *            the MySQL collation/character set index
 * @param jdbcType
 *            from java.sql.Types
 * @param length
 *            length in characters or bytes (for BINARY data).
 */
Field(String tableName, String columnName, int charsetIndex, int jdbcType, int length) {
    this.tableName = tableName;
    this.name = columnName;
    this.length = length;
    this.sqlType = jdbcType;
    this.colFlag = 0;
    this.colDecimals = 0;
    this.collationIndex = charsetIndex;
    this.valueNeedsQuoting = determineNeedsQuoting();

    switch (this.sqlType) {
        case Types.BINARY:
        case Types.VARBINARY:
            this.colFlag |= 128;
            this.colFlag |= 16;
            break;
    }
}
 
Example 2
Source File: DB2ColumnMetadataReader.java    From virtual-schemas with MIT License 6 votes vote down vote up
@Override
public DataType mapJdbcType(final JdbcTypeDescription jdbcTypeDescription) {
    final int size = jdbcTypeDescription.getPrecisionOrSize();
    switch (jdbcTypeDescription.getJdbcType()) {
    case Types.CLOB:
    case Types.OTHER:
        return DataType.createVarChar(DataType.MAX_EXASOL_VARCHAR_SIZE, DataType.ExaCharset.UTF8);
    case Types.TIMESTAMP:
        return DataType.createVarChar(32, DataType.ExaCharset.UTF8);
    case Types.VARCHAR:
    case Types.NVARCHAR:
    case Types.LONGVARCHAR:
    case Types.CHAR:
    case Types.NCHAR:
    case Types.LONGNVARCHAR:
        return getLiteralDataType(size);
    case Types.BINARY:
        return DataType.createChar(size * 2, DataType.ExaCharset.ASCII);
    case Types.VARBINARY:
        return DataType.createVarChar(size * 2, DataType.ExaCharset.ASCII);
    default:
        return super.mapJdbcType(jdbcTypeDescription);
    }
}
 
Example 3
Source File: FirebirdSpecific.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public String sqlType2str(int sqlType) {
	switch(sqlType) {
		case Types.VARCHAR :
			return "VARCHAR";	
		case Types.BOOLEAN :
			return "CHAR(1)";
		case Types.TIME :
		case Types.DATE :
		case Types.TIMESTAMP :
			return "TIMESTAMP";
		case Types.INTEGER :
			return "INTEGER";
		case Types.NUMERIC :
			return "DOUBLE PRECISION";
		case Types.BIGINT :
			return "BIGINT";
		case Types.VARBINARY :
		case Types.BINARY :
			return "CHAR";
	}
	return super.sqlType2str(sqlType);
}
 
Example 4
Source File: DefaultStorageDataTypeContext.java    From registry with Apache License 2.0 5 votes vote down vote up
protected int getSqlType(Schema.Type type) {
    switch (type) {
        case BOOLEAN:
            return Types.BOOLEAN;
        case BYTE:
            return Types.TINYINT;
        case SHORT:
            return Types.SMALLINT;
        case INTEGER:
            return Types.INTEGER;
        case LONG:
            return Types.BIGINT;
        case FLOAT:
            return Types.REAL;
        case DOUBLE:
            return Types.DOUBLE;
        case STRING:
            // it might be a VARCHAR or LONGVARCHAR
            return Types.VARCHAR;
        case BINARY:
            // it might be a VARBINARY or LONGVARBINARY
            return Types.VARBINARY;
        case BLOB:
            return Types.BLOB;
        case NESTED:
        case ARRAY:
            return Types.JAVA_OBJECT;
        default:
            throw new IllegalArgumentException("Not supported type: " + type);
    }
}
 
Example 5
Source File: ExtractXMLToColumns.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public Object getSource(String id, ResultSet rs) throws SQLException
{
	ResultSetMetaData metadata = rs.getMetaData();
	String rv = null;
	switch(metadata.getColumnType(1))
	{
	case Types.BLOB:
		Blob blob = rs.getBlob(1);
		if(blob != null)
		{
			rv = new String(blob.getBytes(1L, (int) blob.length()));
		}
		break;
	case Types.CLOB:
		Clob clob = rs.getClob(1);
		if(clob != null)
		{
			rv = clob.getSubString(1L, (int) clob.length());
		}
		break;
	case Types.CHAR:
	case Types.LONGVARCHAR:
	case Types.VARCHAR:
	case Types.BINARY:
	case Types.VARBINARY:
	case Types.LONGVARBINARY:
		byte[] bytes = rs.getBytes(1);
		if(bytes != null)
		{
			rv = new String(bytes);
		}
		break;
	}
	return rv;
}
 
Example 6
Source File: PgServer.java    From Lealone-Plugins with Apache License 2.0 5 votes vote down vote up
/**
 * Convert the SQL type to a PostgreSQL type
 *
 * @param type the SQL type
 * @return the PostgreSQL type
 */
public static int convertType(final int type) {
    switch (type) {
    case Types.BOOLEAN:
        return PG_TYPE_BOOL;
    case Types.VARCHAR:
        return PG_TYPE_VARCHAR;
    case Types.CLOB:
        return PG_TYPE_TEXT;
    case Types.CHAR:
        return PG_TYPE_BPCHAR;
    case Types.SMALLINT:
        return PG_TYPE_INT2;
    case Types.INTEGER:
        return PG_TYPE_INT4;
    case Types.BIGINT:
        return PG_TYPE_INT8;
    case Types.DECIMAL:
        return PG_TYPE_NUMERIC;
    case Types.REAL:
        return PG_TYPE_FLOAT4;
    case Types.DOUBLE:
        return PG_TYPE_FLOAT8;
    case Types.TIME:
        return PG_TYPE_TIME;
    case Types.DATE:
        return PG_TYPE_DATE;
    case Types.TIMESTAMP:
        return PG_TYPE_TIMESTAMP_NO_TMZONE;
    case Types.VARBINARY:
        return PG_TYPE_BYTEA;
    case Types.BLOB:
        return PG_TYPE_OID;
    case Types.ARRAY:
        return PG_TYPE_TEXTARRAY;
    default:
        return PG_TYPE_UNKNOWN;
    }
}
 
Example 7
Source File: JdbcTypeUtil.java    From canal with Apache License 2.0 5 votes vote down vote up
public static Class<?> jdbcType2javaType(int jdbcType) {
    switch (jdbcType) {
        case Types.BIT:
        case Types.BOOLEAN:
            // return Boolean.class;
        case Types.TINYINT:
            return Byte.TYPE;
        case Types.SMALLINT:
            return Short.class;
        case Types.INTEGER:
            return Integer.class;
        case Types.BIGINT:
            return Long.class;
        case Types.DECIMAL:
        case Types.NUMERIC:
            return BigDecimal.class;
        case Types.REAL:
            return Float.class;
        case Types.FLOAT:
        case Types.DOUBLE:
            return Double.class;
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            return String.class;
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
        case Types.BLOB:
            return byte[].class;
        case Types.DATE:
            return Date.class;
        case Types.TIME:
            return Time.class;
        case Types.TIMESTAMP:
            return Timestamp.class;
        default:
            return String.class;
    }
}
 
Example 8
Source File: MessageDaoImpl.java    From web-qq with Apache License 2.0 5 votes vote down vote up
public int saveMessage(Message message) throws WebQQDaoException {
    try{
        Object[]  args = new Object[] {
                message.getId(),
                message.getContent(),
                new java.sql.Timestamp(
                        message.getSendDate() != null ? message.getSendDate().getTime() : System.currentTimeMillis()),
                message.getSendDeleteFlag(),
                message.getReceiveDeleteFlag(),
                message.getReceiveUser().getUsername(),
                message.getSendUser().getUsername()
        };
        int[]  argTypes = new int[] {
                Types.VARBINARY,
                Types.VARBINARY,
                Types.TIMESTAMP,
                Types.INTEGER,
                Types.INTEGER,
                Types.VARBINARY,
                Types.VARBINARY
        };
        return jdbcTemplate.update(
                SQL_SAVE_MESSAGE,
                args,
                argTypes
        );
    } catch (Exception ex) {
        throw new WebQQDaoException(SQL_SAVE_MESSAGE,ex);
    }

}
 
Example 9
Source File: SpatialFunctions.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Maps a given SQL type to a Java class.
 * This method shall not return primitive types; their wrappers shall be used instead.
 * It may return array of primitive types however.
 * If no match is found, then this method returns {@code null}.
 *
 * <p>The default implementation handles the types declared in {@link Types} class.
 * Subclasses should handle the geometry types declared by spatial extensions.</p>
 *
 * @param  sqlType      SQL type code as one of {@link java.sql.Types} constants.
 * @param  sqlTypeName  data source dependent type name. For User Defined Type (UDT) the name is fully qualified.
 * @return corresponding java type, or {@code null} if unknown.
 */
@SuppressWarnings("fallthrough")
protected Class<?> toJavaType(final int sqlType, final String sqlTypeName) {
    switch (sqlType) {
        case Types.BIT:
        case Types.BOOLEAN:                 return Boolean.class;
        case Types.TINYINT:                 if (!isByteUnsigned) return Byte.class;         // else fallthrough.
        case Types.SMALLINT:                return Short.class;
        case Types.INTEGER:                 return Integer.class;
        case Types.BIGINT:                  return Long.class;
        case Types.REAL:                    return Float.class;
        case Types.FLOAT:                   // Despite the name, this is implemented as DOUBLE in major databases.
        case Types.DOUBLE:                  return Double.class;
        case Types.NUMERIC:                 // Similar to DECIMAL except that it uses exactly the specified precision.
        case Types.DECIMAL:                 return BigDecimal.class;
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:             return String.class;
        case Types.DATE:                    return LocalDate.class;
        case Types.TIME:                    return LocalTime.class;
        case Types.TIMESTAMP:               return LocalDateTime.class;
        case Types.TIME_WITH_TIMEZONE:      return OffsetTime.class;
        case Types.TIMESTAMP_WITH_TIMEZONE: return OffsetDateTime.class;
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:           return byte[].class;
        case Types.ARRAY:                   return Object[].class;
        case Types.OTHER:                   // Database-specific accessed via getObject and setObject.
        case Types.JAVA_OBJECT:             return Object.class;
        default:                            return null;
    }
}
 
Example 10
Source File: GfxdCBArgForSynchPrms.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public String getColumnClassName(int column) throws SQLException {
  if (column > 0 && column <= this.numParams) {
    if (this.dtds != null) {
      return this.dtds[column - 1].getTypeId().getResultSetMetaDataTypeName();
    }
    else {
      switch (this.sqlParamTypes[column - 1]) {
        case Types.BIT:
        case Types.BOOLEAN:
          return "java.lang.Boolean";
        case Types.TINYINT:
          return "java.lang.Integer";
        case Types.SMALLINT:
          return "java.lang.Integer";
        case Types.INTEGER:
          return "java.lang.Integer";
        case Types.BIGINT:
          return "java.lang.Long";
        case Types.FLOAT:
        case Types.REAL:
          return "java.lang.Float";
        case Types.DOUBLE:
          return "java.lang.Double";
        case Types.NUMERIC:
        case Types.DECIMAL:
          return "java.math.BigDecimal";
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
          return "java.lang.String";
        case Types.DATE:
          return "java.sql.Date";
        case Types.TIME:
          return "java.sql.Time";
        case Types.TIMESTAMP:
          return "java.sql.Timestamp";
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
          return "byte[]";
        case BLOB:
          return "java.sql.Blob";
        case CLOB:
          return "java.sql.Clob";
        case SQLXML:
          return "com.pivotal.gemfirexd.internal.iapi.types.XML";
        case JSON:
          return "com.pivotal.gemfirexd.internal.iapi.types.JSON";
        case JAVA_OBJECT:
          final DataValueDescriptor dvd = this.params[column - 1];
          if (dvd != null) {
            try {
              final Object o = dvd.getObject();
              if (o != null) {
                return o.getClass().getName();
              }
            } catch (StandardException se) {
              throw Util.generateCsSQLException(se);
            }
          }
          return "NULL UDT";
        default:
          throw Util.generateCsSQLException(SQLState.UNSUPPORTED_TYPE);
      }
    }
  }
  else {
    throw Util.generateCsSQLException(SQLState.COLUMN_NOT_FOUND,
        Integer.valueOf(column));
  }
}
 
Example 11
Source File: AbstractStringRowIterator.java    From Mycat2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Object getObject(int columnIndex) {
    int columnType = mycatRowMetaData.getColumnType(columnIndex);
    switch (columnType) {
        case Types.NUMERIC: {

        }
        case Types.DECIMAL: {
            return this.getBigDecimal(columnIndex);
        }
        case Types.BIT: {
            return this.getBoolean(columnIndex);
        }
        case Types.TINYINT: {
            return this.getByte(columnIndex);
        }
        case Types.SMALLINT: {
            return this.getShort(columnIndex);
        }
        case Types.INTEGER: {
            return this.getInt(columnIndex);
        }
        case Types.BIGINT: {
            return this.getLong(columnIndex);
        }
        case Types.REAL: {
            return this.getFloat(columnIndex);
        }
        case Types.FLOAT: {

        }
        case Types.DOUBLE: {
            return this.getDouble(columnIndex);
        }
        case Types.BINARY: {

        }
        case Types.VARBINARY: {

        }
        case Types.LONGVARBINARY: {
            return this.getBytes(columnIndex);
        }
        case Types.DATE: {
            return this.getDate(columnIndex);
        }
        case Types.TIME: {
            return this.getTime(columnIndex);
        }
        case Types.TIMESTAMP: {
            return this.getTimestamp(columnIndex);
        }
        case Types.CHAR: {

        }
        case Types.VARCHAR: {

        }
        case Types.LONGVARCHAR: {
            return this.getString(columnIndex);
        }
        case Types.BLOB: {

        }
        case Types.CLOB: {
            return this.getBytes(columnIndex);
        }
        case Types.NULL: {
            return null;
        }
        default:
            throw new RuntimeException("unsupport!");
    }
}
 
Example 12
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 13
Source File: ResultSetMetaData.java    From r-course with MIT License 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: SakaiReport.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private String getColumnValue(ResultSet rs, int colType, int colIndex)
        throws SQLException, IOException {
    String value = "";
    switch (colType) {
        case Types.BIT:
        case Types.JAVA_OBJECT:
            value = handleObject(rs.getObject(colIndex));
            break;
        case Types.BOOLEAN:
            boolean b = rs.getBoolean(colIndex);
            value = Boolean.valueOf(b).toString();
            break;
        case NCLOB: // todo : use rs.getNClob
        case Types.CLOB:
            Clob c = rs.getClob(colIndex);
            if (c != null) {
                value = read(c);
            }
            break;
        case Types.BIGINT:
            value = handleLong(rs, colIndex);
            break;
        case Types.DECIMAL:
        case Types.DOUBLE:
        case Types.FLOAT:
        case Types.REAL:
        case Types.NUMERIC:
            value = handleBigDecimal(rs.getBigDecimal(colIndex));
            break;
        case Types.INTEGER:
        case Types.TINYINT:
        case Types.SMALLINT:
            value = handleInteger(rs, colIndex);
            break;
        case Types.DATE:
            value = handleDate(rs, colIndex);
            break;
        case Types.TIME:
            value = handleTime(rs.getTime(colIndex));
            break;
        case Types.TIMESTAMP:
            value = handleTimestamp(rs.getTimestamp(colIndex));
            break;
        case NVARCHAR: // todo : use rs.getNString
        case NCHAR: // todo : use rs.getNString
        case LONGNVARCHAR: // todo : use rs.getNString
        case Types.LONGVARCHAR:
        case Types.VARCHAR:
        case Types.CHAR:
            value = rs.getString(colIndex);
            break;
        case Types.VARBINARY:
        case Types.BINARY:
            value = handleRaw(rs.getBytes(colIndex));
            break;
        default:
            value = "";
    }


    if (value == null) {
        value = "";
    }

    return value;

}
 
Example 15
Source File: DB2LengthOperatorNode.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
private int getConstantLength( ) throws StandardException
  {
      DataTypeDescriptor typeDescriptor = operand.getTypeServices();
      
      switch( typeDescriptor.getJDBCTypeId())
      {
      case Types.BIGINT:
          return 8;
case Types.BOOLEAN:
      case Types.BIT:
          return 1;
      case Types.BINARY:
      case Types.CHAR:
          return typeDescriptor.getMaximumWidth();
      case Types.DATE:
          return 4;
      case Types.DECIMAL:
      case Types.NUMERIC:
          return typeDescriptor.getPrecision()/2 + 1;
      case Types.DOUBLE:
          return 8;
      case Types.FLOAT:
      case Types.REAL:
      case Types.INTEGER:
          return 4;
      case Types.SMALLINT:
          return 2;
      case Types.TIME:
          return 3;
      case Types.TIMESTAMP:
          return 10;
      case Types.TINYINT:
          return 1;
      case Types.LONGVARCHAR:
      case Types.VARCHAR:
      case Types.LONGVARBINARY:
      case Types.VARBINARY:
      case Types.BLOB:
          return getConstantNodeLength();
      default:
	return -1;
      }
  }
 
Example 16
Source File: LengthOperatorNode.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Bind this operator
 *
 * @param fromList			The query's FROM list
 * @param subqueryList		The subquery list being built as we find SubqueryNodes
 * @param aggregateVector	The aggregate vector being built as we find AggregateNodes
 *
 * @return	The new top of the expression tree.
 *
 * @exception StandardException		Thrown on error
 */

public ValueNode bindExpression(
	FromList	fromList, SubqueryList subqueryList,
	Vector	aggregateVector)
		throws StandardException
{
	TypeId	operandType;

	bindOperand(fromList, subqueryList,
			aggregateVector);

	/*
	** Check the type of the operand - this function is allowed only on
	** string value types.  
	*/
	operandType = operand.getTypeId();
	switch (operandType.getJDBCTypeId())
	{
			case Types.CHAR:
			case Types.VARCHAR:
			case Types.BINARY:
			case Types.VARBINARY:
			case Types.LONGVARBINARY:
			case Types.LONGVARCHAR:
               case Types.BLOB:
               case Types.CLOB:
				break;
		
			default:
				throw StandardException.newException(SQLState.LANG_UNARY_FUNCTION_BAD_TYPE,
										getOperatorString(),
										operandType.getSQLTypeName());
	}

	/*
	** The result type of XXX_length is int.
	*/
	setType(new DataTypeDescriptor(
						TypeId.INTEGER_ID,
						operand.getTypeServices().isNullable()
					)
			);
	return this;
}
 
Example 17
Source File: ParserUtils.java    From CodeGen with MIT License 4 votes vote down vote up
/**
 * 根据Types获取字段类型
 *
 * @see Types
 * @return 对应字段的java类型
 */
public static FieldType getFieldType(Integer sqlType) {
    FieldType fieldType = sqlTypes.get(UNKNOWN_FIELD);
    if (sqlType == null) {
        return fieldType;
    }

    // https://docs.oracle.com/javase/1.5.0/docs/guide/jdbc/getstart/mapping.html
    if (sqlType == Types.INTEGER) {
        fieldType = sqlTypes.get("INTEGER");
    } else if (sqlType == Types.VARCHAR) {
        fieldType = sqlTypes.get("STRING");
    } else if (sqlType == Types.CHAR) {
        fieldType = sqlTypes.get("STRING");
    } else if (sqlType == Types.LONGVARCHAR) {
        fieldType = sqlTypes.get("STRING");
    } else if (sqlType == Types.NVARCHAR) {
        fieldType = sqlTypes.get("STRING");
    } else if (sqlType == Types.NCHAR) {
        fieldType = sqlTypes.get("STRING");
    } else if (sqlType == Types.LONGNVARCHAR) {
        fieldType = sqlTypes.get("STRING");
    } else if (sqlType == Types.NUMERIC) {
        fieldType = sqlTypes.get("DECIMAL");
    } else if (sqlType == Types.DECIMAL) {
        fieldType = sqlTypes.get("DECIMAL");
    } else if (sqlType == Types.BIT) {
        fieldType = sqlTypes.get("BOOLEAN");
    } else if (sqlType == Types.BOOLEAN) {
        fieldType = sqlTypes.get("BOOLEAN");
    } else if (sqlType == Types.TINYINT) {
        fieldType = sqlTypes.get("INTEGER");
    } else if (sqlType == Types.SMALLINT) {
        fieldType = sqlTypes.get("INTEGER");
    } else if (sqlType == Types.BIGINT) {
        fieldType = sqlTypes.get("BIGINT");
    } else if (sqlType == Types.REAL) {
        fieldType = sqlTypes.get("REAL");
    } else if (sqlType == Types.FLOAT) {
        fieldType = sqlTypes.get("FLOAT");
    } else if (sqlType == Types.DOUBLE) {
        fieldType = sqlTypes.get("DOUBLE");
    } else if (sqlType == Types.DATE) {
        // java.sql.Date ?
        fieldType = sqlTypes.get("DATE");
    } else if (sqlType == Types.TIME) {
        // java.sql.Time ?
        fieldType = sqlTypes.get("TIME");
    } else if (sqlType == Types.TIMESTAMP) {
        // java.sql.Timestamp ?
        fieldType = sqlTypes.get("TIMESTAMP");
    } else if (sqlType == Types.BINARY
            || sqlType == Types.VARBINARY) {
        fieldType = sqlTypes.get("BINARY");
    } else if (sqlType == Types.CLOB) {
        fieldType = sqlTypes.get("CLOB");
    } else if (sqlType == Types.BLOB
            || sqlType == Types.LONGVARBINARY) {
        fieldType = sqlTypes.get("BLOB");
    } else {
        // DISTINCT, ARRAY, STRUCT, REF, JAVA_OBJECT.
        return fieldType;
    }
    return fieldType;
}
 
Example 18
Source File: DVDStoreResultSet.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public InputStream getBinaryStream(int columnIndex) throws SQLException {
  if (columnIndex > 0 && columnIndex <= this.numColumns) {
    final TableMetaData metadata = getMetaData();
    final int columnType = metadata.getColumnType(columnIndex);
    switch (columnType) {
      case Types.BINARY:
      case Types.VARBINARY:
      case Types.LONGVARBINARY:
      case Types.BLOB:
        break;

      default:
        throw dataConversionException(
            metadata.getColumnTypeName(columnIndex), "InputStream(BINARY)",
            columnIndex);
    }
    try {
      final byte[] bytes;
      final DataValueDescriptor dvd;
      if (this.currentRowDVDs != null) {
        dvd = this.currentRowDVDs[columnIndex - 1];
      }
      else if (this.pvs != null) {
        dvd = this.pvs.getParameter(columnIndex - 1);
      }
      else {
        throw noCurrentRow();
      }
      if (dvd != null && !dvd.isNull()) {
        this.wasNull = false;
        final StreamStorable ss = (StreamStorable)dvd;
        final InputStream stream = ss.returnStream();
        if (stream != null) {
          return stream;
        }
        else {
          bytes = dvd.getBytes();
        }
      }
      else {
        this.wasNull = true;
        return null;
      }
      if (bytes != null) {
        return new NewByteArrayInputStream(bytes);
      }
      else {
        return null;
      }
    } catch (StandardException se) {
      throw Util.generateCsSQLException(se);
    }
  }
  else {
    throw invalidColumnException(columnIndex);
  }
}
 
Example 19
Source File: OdbcRequestHandler.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Convert {@link java.sql.Types} to binary type constant (See {@link GridBinaryMarshaller} constants).
 *
 * @param sqlType SQL type.
 * @return Binary type.
 */
private static byte sqlTypeToBinary(int sqlType) {
    switch (sqlType) {
        case Types.BIGINT:
            return GridBinaryMarshaller.LONG;

        case Types.BOOLEAN:
            return GridBinaryMarshaller.BOOLEAN;

        case Types.DATE:
            return GridBinaryMarshaller.DATE;

        case Types.DOUBLE:
            return GridBinaryMarshaller.DOUBLE;

        case Types.FLOAT:
        case Types.REAL:
            return GridBinaryMarshaller.FLOAT;

        case Types.NUMERIC:
        case Types.DECIMAL:
            return GridBinaryMarshaller.DECIMAL;

        case Types.INTEGER:
            return GridBinaryMarshaller.INT;

        case Types.SMALLINT:
            return GridBinaryMarshaller.SHORT;

        case Types.TIME:
            return GridBinaryMarshaller.TIME;

        case Types.TIMESTAMP:
            return GridBinaryMarshaller.TIMESTAMP;

        case Types.TINYINT:
            return GridBinaryMarshaller.BYTE;

        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGNVARCHAR:
            return GridBinaryMarshaller.STRING;

        case Types.NULL:
            return GridBinaryMarshaller.NULL;

        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
        default:
            return GridBinaryMarshaller.BYTE_ARR;
    }
}
 
Example 20
Source File: JDBCUtils.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Get the SQLType for the given java.sql.Type type.
 *
 * @param type the java.sql.Type type specifier
 * @return SQLType.the SQLType for this java.sql.Type, or null if it's not recognized
 */
public static SQLType getSQLType(int type) {
    switch (type) {
        case Types.BIT: return SQLType.BIT;
        case Types.TINYINT: return SQLType.TINYINT;
        case Types.SMALLINT: return SQLType.SMALLINT;
        case Types.INTEGER: return SQLType.INTEGER;
        case Types.BIGINT: return SQLType.BIGINT;
        case Types.FLOAT: return SQLType.FLOAT;
        case Types.REAL: return SQLType.REAL;
        case Types.DOUBLE: return SQLType.DOUBLE;
        case Types.NUMERIC: return SQLType.NUMERIC;
        case Types.DECIMAL: return SQLType.DECIMAL;
        case Types.CHAR: return SQLType.CHAR;
        case Types.VARCHAR: return SQLType.VARCHAR;
        case Types.LONGVARCHAR: return SQLType.LONGVARCHAR;
        case Types.DATE: return SQLType.DATE;
        case Types.TIME: return SQLType.TIME;
        case Types.TIMESTAMP: return SQLType.TIMESTAMP;
        case Types.BINARY: return SQLType.BINARY;
        case Types.VARBINARY: return SQLType.VARBINARY;
        case Types.LONGVARBINARY: return SQLType.LONGVARBINARY;
        case Types.NULL: return SQLType.NULL;
        case Types.OTHER: return SQLType.OTHER;
        case Types.JAVA_OBJECT: return SQLType.JAVA_OBJECT;
        case Types.DISTINCT: return SQLType.DISTINCT;
        case Types.STRUCT: return SQLType.STRUCT;
        case Types.ARRAY: return SQLType.ARRAY;
        case Types.BLOB: return SQLType.BLOB;
        case Types.CLOB: return SQLType.CLOB;
        case Types.REF: return SQLType.REF;
        case Types.DATALINK: return SQLType.DATALINK;
        case Types.BOOLEAN: return SQLType.BOOLEAN;
        case Types.LONGNVARCHAR: return SQLType.LONGVARCHAR;
        case Types.NCHAR: return SQLType.CHAR;
        case Types.NCLOB: return SQLType.CLOB;
        case Types.NVARCHAR: return SQLType.VARCHAR;
        case Types.SQLXML: return SQLType.SQLXML;
        case Types.ROWID: return SQLType.ROWID;
        default:
            Logger.getLogger(JDBCUtils.class.getName()).log(Level.WARNING, "Unknown JDBC column type: " + type + ". Returns null.");
            return null;
    }
}