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:Main.java

public static String getCloverTypeFromJdbcType(int jdbcDataType) {
    switch (jdbcDataType) {
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        return "date";
    case Types.ARRAY:
    case Types.BINARY:
    case Types.DATALINK:
    case Types.BLOB:
    case Types.DISTINCT:
    case Types.JAVA_OBJECT:
    case Types.NULL:
    case Types.OTHER:
    case Types.REF:
    case Types.STRUCT:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        System.out.println("Outputting cbyte for Type: " + jdbcDataType);
        return "cbyte";
    case Types.BIT:
    case Types.BOOLEAN:
        return "boolean";
    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.FLOAT:
    case Types.NUMERIC:
    case Types.REAL:
        return "numeric";
    case Types.INTEGER:
    case Types.SMALLINT:
        return "integer";
    case Types.BIGINT:
        return "long";
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.CLOB:
    case Types.LONGVARCHAR:
        return "string";
    }/*from  ww w  . java  2 s. c o  m*/
    System.out.println("Outputting string for unknown Type: " + jdbcDataType);
    return "string";
}

From source file:Main.java

/**
 * Gets the name of the type to be used with the internal dbms
 * //from  ww w . j a v  a 2  s .c om
 * @param type
 *            java.sql.Types constant
 * 
 * @return String
 * 
 * @throws RuntimeException
 *             If the Type is not recognized
 */
public static String getTypeString(int type) {
    switch (type) {
    case Types.BIGINT:
        return "BIGINT";

    case Types.BIT:
    case Types.BOOLEAN:
        return "BOOLEAN";

    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        return "VARCHAR";

    case Types.DATE:
        return "DATE";

    case Types.DECIMAL:
    case Types.NUMERIC:
    case Types.FLOAT:
    case Types.DOUBLE:
    case Types.REAL:
        return "DOUBLE";

    case Types.INTEGER:
        return "INTEGER";

    case Types.SMALLINT:
        return "SHORT";

    case Types.TINYINT:
        return "BYTE";

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

    case Types.TIMESTAMP:
        return "TIMESTAMP";

    case Types.TIME:
        return "TIME";

    default:
        throw new RuntimeException("Cannot edit the type: " + type);
    }
}

From source file:com.espertech.esper.util.TestSQLTypeMapUtil.java

public void testMapping() {
    Map<Integer, Class> testData = new HashMap<Integer, Class>();
    testData.put(Types.CHAR, String.class);
    testData.put(Types.VARCHAR, String.class);
    testData.put(Types.LONGVARCHAR, String.class);
    testData.put(Types.NUMERIC, BigDecimal.class);
    testData.put(Types.DECIMAL, BigDecimal.class);
    testData.put(Types.BIT, Boolean.class);
    testData.put(Types.BOOLEAN, Boolean.class);
    testData.put(Types.TINYINT, Byte.class);
    testData.put(Types.SMALLINT, Short.class);
    testData.put(Types.INTEGER, Integer.class);
    testData.put(Types.BIGINT, Long.class);
    testData.put(Types.REAL, Float.class);
    testData.put(Types.FLOAT, Double.class);
    testData.put(Types.DOUBLE, Double.class);
    testData.put(Types.BINARY, byte[].class);
    testData.put(Types.VARBINARY, byte[].class);
    testData.put(Types.LONGVARBINARY, byte[].class);
    testData.put(Types.DATE, java.sql.Date.class);
    testData.put(Types.TIMESTAMP, java.sql.Timestamp.class);
    testData.put(Types.TIME, java.sql.Time.class);
    testData.put(Types.CLOB, java.sql.Clob.class);
    testData.put(Types.BLOB, java.sql.Blob.class);
    testData.put(Types.ARRAY, java.sql.Array.class);
    testData.put(Types.STRUCT, java.sql.Struct.class);
    testData.put(Types.REF, java.sql.Ref.class);
    testData.put(Types.DATALINK, java.net.URL.class);

    for (int type : testData.keySet()) {
        Class result = SQLTypeMapUtil.sqlTypeToClass(type, null);
        log.debug(".testMapping Mapping " + type + " to " + result.getSimpleName());
        assertEquals(testData.get(type), result);
    }//from   w  w  w  . ja v a2 s.c om

    assertEquals(String.class, SQLTypeMapUtil.sqlTypeToClass(Types.JAVA_OBJECT, "java.lang.String"));
    assertEquals(String.class, SQLTypeMapUtil.sqlTypeToClass(Types.DISTINCT, "java.lang.String"));
}

From source file:org.jspresso.framework.model.persistence.hibernate.dialect.Oracle10gDialect.java

/**
 * {@inheritDoc}//from  w  w w. ja v a 2  s . c om
 */
@Override
protected void registerLargeObjectTypeMappings() {
    super.registerLargeObjectTypeMappings();
    registerColumnType(Types.VARBINARY, "blob");
}

From source file:org.melati.poem.BinaryPoemType.java

/**
 * Constructor./*from  www  .ja v  a  2  s .  c  o m*/
 * @param nullable whether nullable
 * @param size how big
 */
public BinaryPoemType(boolean nullable, int size) {
    super(Types.VARBINARY, "VARBINARY", nullable, size);
}

From source file:au.com.ish.derbydump.derbydump.metadata.Column.java

/**
 * Get a string value for the value in this column in the datarow
 * /* w  w w  .  ja  v a  2s. com*/
 * @param dataRow The row which we are exporting
 * @return an SQL statement compliant string version of the value
 */
public String toString(ResultSet dataRow) throws SQLException {

    switch (getColumnDataType()) {
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.BLOB: {
        Blob obj = dataRow.getBlob(columnName);
        return (obj == null) ? "NULL" : processBinaryData(obj);
    }

    case Types.CLOB: {
        Clob obj = dataRow.getClob(columnName);
        return (obj == null) ? "NULL" : processClobData(obj);
    }

    case Types.CHAR:
    case Types.LONGNVARCHAR:
    case Types.VARCHAR: {
        String obj = dataRow.getString(columnName);
        return (obj == null) ? "NULL" : processStringData(obj);
    }

    case Types.TIME: {
        Time obj = dataRow.getTime(columnName);
        return (obj == null) ? "NULL" : processStringData(obj.toString());
    }

    case Types.DATE: {
        Date obj = dataRow.getDate(columnName);
        return (obj == null) ? "NULL" : processStringData(obj.toString());
    }

    case Types.TIMESTAMP: {
        Timestamp obj = dataRow.getTimestamp(columnName);
        return (obj == null) ? "NULL" : processStringData(obj.toString());
    }

    case Types.SMALLINT: {
        Object obj = dataRow.getObject(columnName);
        return (obj == null) ? "NULL" : obj.toString();
    }

    case Types.BIGINT: {
        Object obj = dataRow.getObject(columnName);
        return (obj == null) ? "NULL" : obj.toString();
    }

    case Types.INTEGER: {
        Object obj = dataRow.getObject(columnName);
        return (obj == null) ? "NULL" : obj.toString();
    }

    case Types.NUMERIC:
    case Types.DECIMAL: {
        BigDecimal obj = dataRow.getBigDecimal(columnName);
        return (obj == null) ? "NULL" : String.valueOf(obj);
    }

    case Types.REAL:
    case Types.FLOAT: {
        Float obj = dataRow.getFloat(columnName);
        // dataRow.getFloat() always returns a value. only way to check the null is wasNull() method
        return (dataRow.wasNull()) ? "NULL" : String.valueOf(obj);
    }

    case Types.DOUBLE: {
        Double obj = dataRow.getDouble(columnName);
        return (dataRow.wasNull()) ? "NULL" : String.valueOf(obj);
    }

    default: {
        Object obj = dataRow.getObject(columnName);
        return (obj == null) ? "NULL" : obj.toString();
    }
    }
}

From source file:org.sakaiproject.mailarchive.impl.conversion.ExtractXMLToColumns.java

public Object getSource(String id, ResultSet rs) throws SQLException {
    ResultSetMetaData metadata = rs.getMetaData();
    String rv = null;//from   www. j a va 2s  .  c  o  m
    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;
    }
    // System.out.println("getSource(" + id + ") \n" + rv + "\n");
    return rv;
}

From source file:org.executequery.gui.resultset.TableCellData.java

public boolean isBlob() {

    return (dataType == Types.BLOB || dataType == Types.BINARY || dataType == Types.VARBINARY
            || dataType == Types.LONGVARBINARY);
}

From source file:com.trackplus.ddl.GenericStringValueConverter.java

protected String extractColumnValue(ResultSet resultSet, int columnIdx, int jdbcType)
        throws SQLException, DDLException {
    String value = resultSet.getString(columnIdx);
    if (value != null) {
        switch (jdbcType) {
        case Types.NUMERIC:
        case Types.DECIMAL:
            break;
        case Types.BIT:
        case Types.BOOLEAN:
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
        case Types.BIGINT:
        case Types.REAL:
        case Types.FLOAT:
        case Types.DOUBLE: {
            break;
        }//from w  w w.  j a v  a 2 s.  co m

        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.TIME:
        case Types.CLOB:
        case Types.ARRAY:
        case Types.REF: {
            value = "'" + value.replaceAll("'", "''") + "'";
            break;
        }
        case Types.DATE:
        case Types.TIMESTAMP: {
            Date d = resultSet.getDate(columnIdx);
            Calendar cal = Calendar.getInstance();
            cal.setTime(d);
            int year = cal.get(Calendar.YEAR);
            if (year < 1900) {
                throw new DDLException("Invalid date:" + d);
            } else {
                value = "'" + value + "'";
            }
            break;
        }
        case Types.BLOB:
        case Types.LONGVARBINARY: {
            Blob blobValue = resultSet.getBlob(columnIdx);
            String str = new String(Base64.encodeBase64(blobValue.getBytes(1l, (int) blobValue.length())));
            value = "'" + str + "'";
            break;
        }
        default:
            break;
        }
    }
    return value;
}

From source file:org.sakaiproject.content.impl.serialize.impl.conversion.Type1BlobCollectionConversionHandler.java

public Object getSource(String id, ResultSet rs) throws SQLException {
    ResultSetMetaData metadata = rs.getMetaData();
    String rv = null;/*from w ww  .  j a  v a 2 s .c o  m*/
    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;
    }
    //System.out.println("getSource(" + id + ") \n" + rv + "\n");
    return rv;
}