Example usage for java.sql Types VARBINARY

List of usage examples for java.sql Types VARBINARY

Introduction

In this page you can find the example usage for java.sql Types VARBINARY.

Prototype

int VARBINARY

To view the source code for java.sql Types VARBINARY.

Click Source Link

Document

The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type VARBINARY.

Usage

From source file:com.splicemachine.db.impl.sql.compile.QueryTreeNode.java

/**
 * Get a ConstantNode to represent a typed null value.
 *
 * @param type Type of the null node.//from  w w  w  . j  ava  2  s. co  m
 * @throws StandardException Thrown on error
 * @return A ConstantNode with the specified type, and a value of null
 */
public ConstantNode getNullNode(DataTypeDescriptor type) throws StandardException {
    int constantNodeType;
    switch (type.getTypeId().getJDBCTypeId()) {
    case Types.VARCHAR:
        constantNodeType = C_NodeTypes.VARCHAR_CONSTANT_NODE;
        break;
    case Types.CHAR:
        constantNodeType = C_NodeTypes.CHAR_CONSTANT_NODE;
        break;
    case Types.TINYINT:
        constantNodeType = C_NodeTypes.TINYINT_CONSTANT_NODE;
        break;
    case Types.SMALLINT:
        constantNodeType = C_NodeTypes.SMALLINT_CONSTANT_NODE;
        break;
    case Types.INTEGER:
        constantNodeType = C_NodeTypes.INT_CONSTANT_NODE;
        break;
    case Types.BIGINT:
        constantNodeType = C_NodeTypes.LONGINT_CONSTANT_NODE;
        break;
    case Types.REAL:
        constantNodeType = C_NodeTypes.FLOAT_CONSTANT_NODE;
        break;
    case Types.DOUBLE:
        constantNodeType = C_NodeTypes.DOUBLE_CONSTANT_NODE;
        break;
    case Types.NUMERIC:
    case Types.DECIMAL:
        constantNodeType = C_NodeTypes.DECIMAL_CONSTANT_NODE;
        break;
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        constantNodeType = C_NodeTypes.USERTYPE_CONSTANT_NODE;
        break;
    case Types.BINARY:
        constantNodeType = C_NodeTypes.BIT_CONSTANT_NODE;
        break;
    case Types.VARBINARY:
        constantNodeType = C_NodeTypes.VARBIT_CONSTANT_NODE;
        break;
    case Types.LONGVARCHAR:
        constantNodeType = C_NodeTypes.LONGVARCHAR_CONSTANT_NODE;
        break;
    case Types.CLOB:
        constantNodeType = C_NodeTypes.CLOB_CONSTANT_NODE;
        break;
    case Types.LONGVARBINARY:
        constantNodeType = C_NodeTypes.LONGVARBIT_CONSTANT_NODE;
        break;
    case Types.BLOB:
        constantNodeType = C_NodeTypes.BLOB_CONSTANT_NODE;
        break;
    case JDBC40Translation.SQLXML:
        constantNodeType = C_NodeTypes.XML_CONSTANT_NODE;
        break;
    case Types.BOOLEAN:
        constantNodeType = C_NodeTypes.BOOLEAN_CONSTANT_NODE;
        break;
    default:
        if (type.getTypeId().userType()) {
            constantNodeType = C_NodeTypes.USERTYPE_CONSTANT_NODE;
        } else {
            throw StandardException.newException(SQLState.LANG_NONULL_DATATYPE,
                    type.getTypeId().getSQLTypeName());
        }
    }

    ConstantNode constantNode = (ConstantNode) getNodeFactory().getNode(constantNodeType, type.getTypeId(), cm);

    constantNode.setType(type.getNullabilityType(true));

    return constantNode;
}

From source file:org.siphon.jssql.SqlExecutor.java

private String translateTypeName(int columnType, String columnTypeName) {
    switch (columnType) {
    case Types.VARCHAR:
    case Types.CHAR:
    case Types.NCHAR:
    case Types.NVARCHAR:
    case Types.LONGVARCHAR:
    case Types.LONGNVARCHAR:
        return "STRING";

    case Types.INTEGER:
    case Types.SMALLINT:
        return "INT";
    case Types.BIGINT:
        return "LONG";
    case Types.FLOAT:
        return "FLOAT";
    case Types.REAL:
    case Types.DOUBLE:
        return "DOUBLE";
    case Types.NUMERIC:
    case Types.DECIMAL:
        return "DECIMAL";

    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
    case Types.TIME_WITH_TIMEZONE:
        return "DATE";

    case Types.ROWID:
        return "ROWID";

    case Types.BLOB:
        return "BINARY"; // return "BLOB";

    case Types.CLOB:
        return "STRING"; // return "CLOB";

    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        return "BINARY";

    case Types.BOOLEAN:
        return "BOOLEAN";

    case Types.ARRAY:
        return "ARRAY";

    case Types.OTHER:
        return columnTypeName.toUpperCase();

    default:/*from ww w . j  ava 2s .  co  m*/
        return "UNKNOWN";
    }
}

From source file:org.pentaho.di.jdbc.Support.java

/**
 * Get a String describing the supplied JDBC type constant.
 *
 * @param jdbcType The constant to be decoded.
 * @return The text decode of the type constant as a <code>String</code>.
 *///from  w w  w. j a  v  a  2s  .c  o  m
static String getJdbcTypeName(int jdbcType) {
    switch (jdbcType) {
    case java.sql.Types.ARRAY:
        return "ARRAY";
    case java.sql.Types.BIGINT:
        return "BIGINT";
    case java.sql.Types.BINARY:
        return "BINARY";
    case java.sql.Types.BIT:
        return "BIT";
    case java.sql.Types.BLOB:
        return "BLOB";
    case java.sql.Types.BOOLEAN:
        return "BOOLEAN";
    case java.sql.Types.CHAR:
        return "CHAR";
    case java.sql.Types.CLOB:
        return "CLOB";
    //            case JtdsStatement.DATALINK:       return "DATALINK";
    case java.sql.Types.DATE:
        return "DATE";
    case java.sql.Types.DECIMAL:
        return "DECIMAL";
    case java.sql.Types.DISTINCT:
        return "DISTINCT";
    case java.sql.Types.DOUBLE:
        return "DOUBLE";
    case java.sql.Types.FLOAT:
        return "FLOAT";
    case java.sql.Types.INTEGER:
        return "INTEGER";
    case java.sql.Types.JAVA_OBJECT:
        return "JAVA_OBJECT";
    case java.sql.Types.LONGVARBINARY:
        return "LONGVARBINARY";
    case java.sql.Types.LONGVARCHAR:
        return "LONGVARCHAR";
    case java.sql.Types.NULL:
        return "NULL";
    case java.sql.Types.NUMERIC:
        return "NUMERIC";
    case java.sql.Types.OTHER:
        return "OTHER";
    case java.sql.Types.REAL:
        return "REAL";
    case java.sql.Types.REF:
        return "REF";
    case java.sql.Types.SMALLINT:
        return "SMALLINT";
    case java.sql.Types.STRUCT:
        return "STRUCT";
    case java.sql.Types.TIME:
        return "TIME";
    case java.sql.Types.TIMESTAMP:
        return "TIMESTAMP";
    case java.sql.Types.TINYINT:
        return "TINYINT";
    case java.sql.Types.VARBINARY:
        return "VARBINARY";
    case java.sql.Types.VARCHAR:
        return "VARCHAR";
    default:
        return "ERROR";
    }
}

From source file:org.nuclos.server.dblayer.impl.standard.StandardSqlDBAccess.java

protected static DbGenericType getDbGenericType(int sqlType, String typeName) {
    switch (sqlType) {
    case Types.VARCHAR:
    case Types.NVARCHAR:
    case Types.NCHAR:
    case Types.CHAR:
        return DbGenericType.VARCHAR;
    case Types.NUMERIC:
    case Types.DECIMAL:
        return DbGenericType.NUMERIC;
    case Types.BIT:
    case Types.BOOLEAN:
        return DbGenericType.BOOLEAN;
    case Types.DATE:
        return DbGenericType.DATE;
    case Types.BLOB:
    case Types.VARBINARY:
    case Types.BINARY:
    case Types.LONGVARBINARY:
        return DbGenericType.BLOB;
    case Types.CLOB:
    case Types.LONGVARCHAR:
        return DbGenericType.CLOB;
    case Types.TIMESTAMP:
        return DbGenericType.DATETIME;
    default://ww w .  jav a 2s .c  o  m
        return null;
    }
}

From source file:org.cloudgraph.rdb.service.JDBCSupport.java

protected void execute(PlasmaType type, StringBuilder sql, Map<String, PropertyPair> values, Connection con) {
    PreparedStatement statement = null;
    List<InputStream> streams = null;
    try {//from www  . j a va2 s . c o m
        if (log.isDebugEnabled()) {
            log.debug("execute: " + sql.toString());
            StringBuilder paramBuf = createParamDebug(values);
            log.debug("params: " + paramBuf.toString());
        }
        statement = con.prepareStatement(sql.toString());
        for (PropertyPair pair : values.values()) {
            PlasmaProperty valueProp = pair.getProp();
            if (pair.getValueProp() != null)
                valueProp = pair.getValueProp();

            int jdbcType = converter.toJDBCDataType(valueProp, pair.getValue());
            Object jdbcValue = converter.toJDBCDataValue(valueProp, pair.getValue());
            if (jdbcType != Types.BLOB && jdbcType != Types.VARBINARY) {
                statement.setObject(pair.getColumn(), jdbcValue, jdbcType);
            } else {
                byte[] bytes = (byte[]) jdbcValue;
                long len = bytes.length;
                ByteArrayInputStream is = new ByteArrayInputStream(bytes);
                statement.setBinaryStream(pair.getColumn(), is, len);
                if (streams == null)
                    streams = new ArrayList<InputStream>();
                streams.add(is);
            }

            if (pair.getOldValue() != null) {
                Object jdbcOldValue = converter.toJDBCDataValue(valueProp, pair.getOldValue());
                if (jdbcType != Types.BLOB && jdbcType != Types.VARBINARY) {
                    statement.setObject(pair.getOldValueColumn(), jdbcOldValue, jdbcType);
                } else {
                    byte[] bytes = (byte[]) jdbcOldValue;
                    long len = bytes.length;
                    ByteArrayInputStream is = new ByteArrayInputStream(bytes);
                    statement.setBinaryStream(pair.getOldValueColumn(), is, len);
                    if (streams == null)
                        streams = new ArrayList<InputStream>();
                    streams.add(is);
                }
            }
        }
        statement.executeUpdate();
    } catch (Throwable t) {
        throw new DataAccessException(t);
    } finally {
        try {
            if (statement != null)
                statement.close();
        } catch (SQLException e) {
            log.error(e.getMessage(), e);
        }
        if (streams != null)
            try {
                for (InputStream stream : streams)
                    stream.close();
            } catch (IOException e) {
                log.error(e.getMessage(), e);
            }

    }
}

From source file:com.squid.kraken.v4.caching.redis.datastruct.RawMatrix.java

public static String getJavaDatatype(int colType) {

    switch (colType) {
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        return "java.lang.String";

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

    case Types.BIT:
        return "boolean";

    case Types.TINYINT:
        return "byte";

    case Types.SMALLINT:
        return "short";

    case Types.INTEGER:
        return "int";

    case Types.BIGINT:
        return "long";

    case Types.REAL:
        return "float";

    case Types.FLOAT:
    case Types.DOUBLE:
        return "double";

    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        return "byte[]";

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

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

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

    case Types.OTHER:
        return "java.lang.Object";
    default:/*from  ww  w  . ja  v  a  2 s. c om*/
        return null;
    }
}

From source file:org.pentaho.di.jdbc.Support.java

/**
 * Retrieve the fully qualified java class name for the
 * supplied JDBC Types constant.// w w  w.  j a  v  a  2s.  com
 *
 * @param jdbcType The JDBC Types constant.
 * @return The fully qualified java class name as a <code>String</code>.
 */
static String getClassName(int jdbcType) {
    switch (jdbcType) {
    case java.sql.Types.BOOLEAN:
    case java.sql.Types.BIT:
        return "java.lang.Boolean";

    case java.sql.Types.TINYINT:
    case java.sql.Types.SMALLINT:
    case java.sql.Types.INTEGER:
        return "java.lang.Integer";

    case java.sql.Types.BIGINT:
        return "java.lang.Long";

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

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

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

    case java.sql.Types.CHAR:
    case java.sql.Types.VARCHAR:
        return "java.lang.String";

    case java.sql.Types.BINARY:
    case java.sql.Types.VARBINARY:
        return "[B";

    case java.sql.Types.LONGVARBINARY:
    case java.sql.Types.BLOB:
        return "java.sql.Blob";

    case java.sql.Types.LONGVARCHAR:
    case java.sql.Types.CLOB:
        return "java.sql.Clob";

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

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

    case java.sql.Types.TIMESTAMP:
        return "java.sql.Timestamp";
    default:
        break;
    }

    return "java.lang.Object";
}

From source file:com.squid.kraken.v4.caching.redis.datastruct.RawMatrix.java

public static boolean isPrimitiveType(int colType) {

    switch (colType) {

    case Types.BIT:
    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.INTEGER:
    case Types.BIGINT:
    case Types.REAL:
    case Types.FLOAT:
    case Types.DOUBLE:
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        return true;

    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
    case Types.NUMERIC:
    case Types.DECIMAL:
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        return false;

    default:/*from   w  ww.  j a va2 s .c o m*/
        return false;
    }
}

From source file:org.jumpmind.symmetric.db.ase.AseTriggerTemplate.java

@Override
protected String buildKeyVariablesDeclare(Column[] columns, String prefix) {
    String text = "";
    for (int i = 0; i < columns.length; i++) {
        text += "declare @" + prefix + "pk" + i + " ";
        switch (columns[i].getMappedTypeCode()) {
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
        case Types.BIGINT:
            // ASE does not support bigint
            text += "NUMERIC(18,0)\n";
            break;
        case Types.NUMERIC:
        case Types.DECIMAL:
            // Use same default scale and precision used by Sybase ASA
            // for a decimal with unspecified scale and precision.
            text += "decimal(30,6)\n";
            break;
        case Types.FLOAT:
        case Types.REAL:
        case Types.DOUBLE:
            text += "float\n";
            break;
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            text += "varchar(1000)\n";
            break;
        case Types.DATE:
            text += "date\n";
            break;
        case Types.TIME:
            text += "time\n";
            break;
        case Types.TIMESTAMP:
            text += "datetime\n";
            break;
        case Types.BOOLEAN:
        case Types.BIT:
            text += "bit\n";
            break;
        case Types.CLOB:
            text += "varchar(32767)\n";
            break;
        case Types.BLOB:
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
        case -10: // SQL-Server ntext binary type
            text += "varbinary(32767)\n";
            break;
        case Types.OTHER:
            text += "varbinary(32767)\n";
            break;
        default://from w ww.jav  a  2s .  com
            if (columns[i].getJdbcTypeName() != null
                    && columns[i].getJdbcTypeName().equalsIgnoreCase("interval")) {
                text += "interval";
                break;
            }
            throw new NotImplementedException(columns[i] + " is of type " + columns[i].getMappedType());
        }
    }

    return text;
}

From source file:org.cloudgraph.rdb.service.JDBCSupport.java

protected void executeInsert(PlasmaType type, StringBuilder sql, Map<String, PropertyPair> values,
        Connection con) {/*from   www.  j  a va 2s  .c om*/
    PreparedStatement statement = null;
    List<InputStream> streams = null;
    try {

        if (log.isDebugEnabled()) {
            log.debug("execute: " + sql.toString());
            StringBuilder paramBuf = createParamDebug(values);
            log.debug("params: " + paramBuf.toString());
        }

        statement = con.prepareStatement(sql.toString());

        for (PropertyPair pair : values.values()) {
            PlasmaProperty valueProp = pair.getProp();
            if (pair.getValueProp() != null)
                valueProp = pair.getValueProp();
            int jdbcType = converter.toJDBCDataType(valueProp, pair.getValue());
            Object jdbcValue = converter.toJDBCDataValue(valueProp, pair.getValue());
            if (jdbcType != Types.BLOB && jdbcType != Types.VARBINARY) {
                statement.setObject(pair.getColumn(), jdbcValue, jdbcType);
            } else {
                byte[] bytes = (byte[]) jdbcValue;
                long len = bytes.length;
                ByteArrayInputStream is = new ByteArrayInputStream(bytes);
                statement.setBinaryStream(pair.getColumn(), is, len);
                if (streams == null)
                    streams = new ArrayList<InputStream>();
                streams.add(is);
            }
        }

        statement.execute();
    } catch (Throwable t) {
        throw new DataAccessException(t);
    } finally {
        try {
            if (statement != null)
                statement.close();
        } catch (SQLException e) {
            log.error(e.getMessage(), e);
        }
        if (streams != null)
            try {
                for (InputStream stream : streams)
                    stream.close();
            } catch (IOException e) {
                log.error(e.getMessage(), e);
            }

    }
}